home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Source / GNU / cc / c-typeck.c < prev    next >
C/C++ Source or Header  |  1994-06-24  |  196KB  |  6,291 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file is part of the C front end.
  22.    It contains routines to build C expressions given their operands,
  23.    including computing the types of the result, C-specific error checks,
  24.    and some optimization.
  25.  
  26.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  27.    and to process initializations in declarations (since they work
  28.    like a strange sort of assignment).  */
  29.  
  30. #include "config.h"
  31. #include <stdio.h>
  32. #include "tree.h"
  33. #include "c-tree.h"
  34. #include "flags.h"
  35.  
  36. /* Nonzero if we've already printed a "partly bracketed initializer"
  37.    message within this initializer.  */
  38. static int partial_bracket_mentioned = 0;
  39.  
  40. extern char *index ();
  41. extern char *rindex ();
  42.  
  43. int mark_addressable ();
  44. static tree convert_for_assignment ();
  45. static void warn_for_assignment ();
  46. static int function_types_compatible_p ();
  47. static int type_lists_compatible_p ();
  48. int self_promoting_args_p ();
  49. static int self_promoting_type_p ();
  50. static int comp_target_types ();
  51. static tree pointer_int_sum ();
  52. static tree pointer_diff ();
  53. static tree convert_sequence ();
  54. static tree unary_complex_lvalue ();
  55. static tree process_init_constructor ();
  56. static tree convert_arguments ();
  57. static char *get_spelling ();
  58. static tree digest_init ();
  59. static void pedantic_lvalue_warning ();
  60. tree truthvalue_conversion ();
  61. void incomplete_type_error ();
  62. void readonly_warning ();
  63. static tree internal_build_compound_expr ();
  64.  
  65. void process_init_element ();
  66.  
  67. /* Do `exp = require_complete_type (exp);' to make sure exp
  68.    does not have an incomplete type.  (That includes void types.)  */
  69.  
  70. tree
  71. require_complete_type (value)
  72.      tree value;
  73. {
  74.   tree type = TREE_TYPE (value);
  75.  
  76.   /* First, detect a valid value with a complete type.  */
  77.   if (TYPE_SIZE (type) != 0
  78.       && type != void_type_node)
  79.     return value;
  80.  
  81.   incomplete_type_error (value, type);
  82.   return error_mark_node;
  83. }
  84.  
  85. /* Print an error message for invalid use of an incomplete type.
  86.    VALUE is the expression that was used (or 0 if that isn't known)
  87.    and TYPE is the type that was invalid.  */
  88.  
  89. void
  90. incomplete_type_error (value, type)
  91.      tree value;
  92.      tree type;
  93. {
  94.   char *errmsg;
  95.  
  96.   /* Avoid duplicate error message.  */
  97.   if (TREE_CODE (type) == ERROR_MARK)
  98.     return;
  99.  
  100.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  101.              || TREE_CODE (value) == PARM_DECL))
  102.     error ("`%s' has an incomplete type",
  103.        IDENTIFIER_POINTER (DECL_NAME (value)));
  104.   else
  105.     {
  106.     retry:
  107.       /* We must print an error message.  Be clever about what it says.  */
  108.  
  109.       switch (TREE_CODE (type))
  110.     {
  111.     case RECORD_TYPE:
  112.       errmsg = "invalid use of undefined type `struct %s'";
  113.       break;
  114.  
  115.     case UNION_TYPE:
  116.       errmsg = "invalid use of undefined type `union %s'";
  117.       break;
  118.  
  119.     case ENUMERAL_TYPE:
  120.       errmsg = "invalid use of undefined type `enum %s'";
  121.       break;
  122.  
  123.     case VOID_TYPE:
  124.       error ("invalid use of void expression");
  125.       return;
  126.  
  127.     case ARRAY_TYPE:
  128.       if (TYPE_DOMAIN (type))
  129.         {
  130.           type = TREE_TYPE (type);
  131.           goto retry;
  132.         }
  133.       error ("invalid use of array with unspecified bounds");
  134.       return;
  135.  
  136.     default:
  137.       abort ();
  138.     }
  139.  
  140.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  141.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  142.       else
  143.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  144.     error ("invalid use of incomplete typedef `%s'",
  145.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  146.     }
  147. }
  148.  
  149. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  150.    as well as those of TYPE.  */
  151.  
  152. static tree
  153. qualify_type (type, like)
  154.      tree type, like;
  155. {
  156.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  157.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  158.   return c_build_type_variant (type, constflag, volflag);
  159. }
  160.  
  161. /* Return the common type of two types.
  162.    We assume that comptypes has already been done and returned 1;
  163.    if that isn't so, this may crash.  In particular, we assume that qualifiers
  164.    match.
  165.  
  166.    This is the type for the result of most arithmetic operations
  167.    if the operands have the given two types.  */
  168.  
  169. tree
  170. common_type (t1, t2)
  171.      tree t1, t2;
  172. {
  173.   register enum tree_code code1;
  174.   register enum tree_code code2;
  175.  
  176.   /* Save time if the two types are the same.  */
  177.  
  178.   if (t1 == t2) return t1;
  179.  
  180.   /* If one type is nonsense, use the other.  */
  181.   if (t1 == error_mark_node)
  182.     return t2;
  183.   if (t2 == error_mark_node)
  184.     return t1;
  185.  
  186.   /* Treat an enum type as the unsigned integer type of the same width.  */
  187.  
  188.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  189.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  190.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  191.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  192.  
  193.   code1 = TREE_CODE (t1);
  194.   code2 = TREE_CODE (t2);
  195.  
  196.   /* If one type is complex, form the common type
  197.      of the non-complex components,
  198.      then make that complex.  */
  199.   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
  200.     {
  201.       tree subtype1, subtype2, subtype;
  202.       if (code1 == COMPLEX_TYPE)
  203.     subtype1 = TREE_TYPE (t1);
  204.       else
  205.     subtype1 = t1;
  206.       if (code2 == COMPLEX_TYPE)
  207.     subtype2 = TREE_TYPE (t2);
  208.       else
  209.     subtype2 = t2;
  210.       subtype = common_type (subtype1, subtype2);
  211.       return build_complex_type (subtype);
  212.     }
  213.  
  214.   switch (code1)
  215.     {
  216.     case INTEGER_TYPE:
  217.     case REAL_TYPE:
  218.       /* If only one is real, use it as the result.  */
  219.  
  220.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  221.     return t1;
  222.  
  223.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  224.     return t2;
  225.  
  226.       /* Both real or both integers; use the one with greater precision.  */
  227.  
  228.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  229.     return t1;
  230.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  231.     return t2;
  232.  
  233.       /* Same precision.  Prefer longs to ints even when same size.  */
  234.  
  235.       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
  236.       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
  237.     return long_unsigned_type_node;
  238.  
  239.       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
  240.       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
  241.     {
  242.       /* But preserve unsignedness from the other type,
  243.          since long cannot hold all the values of an unsigned int.  */
  244.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  245.         return long_unsigned_type_node;
  246.       return long_integer_type_node;
  247.     }
  248.  
  249.       /* Otherwise prefer the unsigned one.  */
  250.  
  251.       if (TREE_UNSIGNED (t1))
  252.     return t1;
  253.       else return t2;
  254.  
  255.     case POINTER_TYPE:
  256.       /* For two pointers, do this recursively on the target type,
  257.      and combine the qualifiers of the two types' targets.  */
  258.       /* This code was turned off; I don't know why.
  259.      But ANSI C specifies doing this with the qualifiers.
  260.      So I turned it on again.  */
  261.       {
  262.     tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  263.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  264.     int constp
  265.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  266.     int volatilep
  267.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  268.     return build_pointer_type (c_build_type_variant (target, constp, volatilep));
  269.       }
  270. #if 0
  271.       return build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  272. #endif
  273.  
  274.     case ARRAY_TYPE:
  275.       {
  276.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  277.     /* Save space: see if the result is identical to one of the args.  */
  278.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  279.       return t1;
  280.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  281.       return t2;
  282.     /* Merge the element types, and have a size if either arg has one.  */
  283.     return build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  284.       }
  285.  
  286.     case FUNCTION_TYPE:
  287.       /* Function types: prefer the one that specified arg types.
  288.      If both do, merge the arg types.  Also merge the return types.  */
  289.       {
  290.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  291.     tree p1 = TYPE_ARG_TYPES (t1);
  292.     tree p2 = TYPE_ARG_TYPES (t2);
  293.     int len;
  294.     tree newargs, n;
  295.     int i;
  296.  
  297.     /* Save space: see if the result is identical to one of the args.  */
  298.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  299.       return t1;
  300.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  301.       return t2;
  302.  
  303.     /* Simple way if one arg fails to specify argument types.  */
  304.     if (TYPE_ARG_TYPES (t1) == 0)
  305.       return build_function_type (valtype, TYPE_ARG_TYPES (t2));
  306.     if (TYPE_ARG_TYPES (t2) == 0)
  307.       return build_function_type (valtype, TYPE_ARG_TYPES (t1));
  308.  
  309.     /* If both args specify argument types, we must merge the two
  310.        lists, argument by argument.  */
  311.  
  312.     len = list_length (p1);
  313.     newargs = 0;
  314.  
  315.     for (i = 0; i < len; i++)
  316.       newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
  317.  
  318.     n = newargs;
  319.  
  320.     for (; p1;
  321.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  322.       {
  323.         /* A null type means arg type is not specified.
  324.            Take whatever the other function type has.  */
  325.         if (TREE_VALUE (p1) == 0)
  326.           {
  327.         TREE_VALUE (n) = TREE_VALUE (p2);
  328.         goto parm_done;
  329.           }
  330.         if (TREE_VALUE (p2) == 0)
  331.           {
  332.         TREE_VALUE (n) = TREE_VALUE (p1);
  333.         goto parm_done;
  334.           }
  335.           
  336.         /* Given  wait (union {union wait *u; int *i} *)
  337.            and  wait (union wait *),
  338.            prefer  union wait *  as type of parm.  */
  339.         if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
  340.         && TREE_VALUE (p1) != TREE_VALUE (p2))
  341.           {
  342.         tree memb;
  343.         for (memb = TYPE_FIELDS (TREE_VALUE (p1));
  344.              memb; memb = TREE_CHAIN (memb))
  345.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
  346.             {
  347.               TREE_VALUE (n) = TREE_VALUE (p2);
  348.               if (pedantic)
  349.             pedwarn ("function types not truly compatible in ANSI C");
  350.               goto parm_done;
  351.             }
  352.           }
  353.         if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
  354.         && TREE_VALUE (p2) != TREE_VALUE (p1))
  355.           {
  356.         tree memb;
  357.         for (memb = TYPE_FIELDS (TREE_VALUE (p2));
  358.              memb; memb = TREE_CHAIN (memb))
  359.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
  360.             {
  361.               TREE_VALUE (n) = TREE_VALUE (p1);
  362.               if (pedantic)
  363.             pedwarn ("function types not truly compatible in ANSI C");
  364.               goto parm_done;
  365.             }
  366.           }
  367.         TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  368.       parm_done: ;
  369.       }
  370.  
  371.     return build_function_type (valtype, newargs);
  372.       }
  373.  
  374.     default:
  375.       return t1;
  376.     }
  377.  
  378. }
  379.  
  380. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  381.    or various other operations.  Return 2 if they are compatible
  382.    but a warning may be needed if you use them together.  */
  383.  
  384. int
  385. comptypes (type1, type2)
  386.      tree type1, type2;
  387. {
  388.   register tree t1 = type1;
  389.   register tree t2 = type2;
  390.  
  391.   /* Suppress errors caused by previously reported errors.  */
  392.  
  393.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  394.     return 1;
  395.  
  396.   /* Treat an enum type as the unsigned integer type of the same width.  */
  397.  
  398.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  399.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  400.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  401.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  402.  
  403.   if (t1 == t2)
  404.     return 1;
  405.  
  406.   /* Different classes of types can't be compatible.  */
  407.  
  408.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  409.  
  410.   /* Qualifiers must match.  */
  411.  
  412.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  413.     return 0;
  414.   if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
  415.     return 0;
  416.  
  417.   /* Allow for two different type nodes which have essentially the same
  418.      definition.  Note that we already checked for equality of the type
  419.      type qualifiers (just above).  */
  420.  
  421.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  422.     return 1;
  423.  
  424.   switch (TREE_CODE (t1))
  425.     {
  426.     case POINTER_TYPE:
  427.       return (TREE_TYPE (t1) == TREE_TYPE (t2)
  428.           ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  429.  
  430.     case FUNCTION_TYPE:
  431.       return function_types_compatible_p (t1, t2);
  432.  
  433.     case ARRAY_TYPE:
  434.       {
  435.     /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  436.     int val = 1;
  437.     tree d1 = TYPE_DOMAIN (t1);
  438.     tree d2 = TYPE_DOMAIN (t2);
  439.  
  440.     /* Target types must match incl. qualifiers.  */
  441.     if (TREE_TYPE (t1) != TREE_TYPE (t2)
  442.         && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  443.       return 0;
  444.  
  445.     /* Sizes must match unless one is missing or variable.  */
  446.     if (d1 == 0 || d2 == 0 || d1 == d2
  447.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  448.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  449.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  450.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  451.       return val;
  452.  
  453.     return (((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  454.           == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  455.          && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  456.              == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  457.          && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  458.              == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  459.          && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  460.              == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))))
  461.         ? val : 0);
  462.       }
  463.  
  464.     case RECORD_TYPE:
  465.       if (maybe_objc_comptypes (t1, t2, 0) == 1)
  466.     return 1;
  467.     }
  468.   return 0;
  469. }
  470.  
  471. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  472.    ignoring their qualifiers.  */
  473.  
  474. static int
  475. comp_target_types (ttl, ttr)
  476.      tree ttl, ttr;
  477. {
  478.   int val;
  479.  
  480.   /* Give maybe_objc_comptypes a crack at letting these types through.  */
  481.   if (val = maybe_objc_comptypes (ttl, ttr, 1) >= 0)
  482.     return val;
  483.  
  484. #ifdef NEXT_SEMANTICS
  485.   if (! pedantic)
  486.     {
  487.       /* Ignore pointer qualifiers recursively.
  488.      This way char ** and const char ** are compatible.  */
  489.       ttl = TYPE_MAIN_VARIANT (TREE_TYPE (ttl));
  490.       ttr = TYPE_MAIN_VARIANT (TREE_TYPE (ttr));
  491.       
  492.       if (TREE_CODE (ttl) == POINTER_TYPE 
  493.       && TREE_CODE (ttr) == POINTER_TYPE)
  494.     return comp_target_types (ttl, ttr);
  495.       else
  496.     return comptypes (ttl, ttr);
  497.     }
  498. #endif
  499.  
  500.   val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  501.            TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  502.  
  503.   if (val == 2 && pedantic)
  504.     pedwarn ("types are not quite compatible");
  505.   return val;
  506. }
  507.  
  508. /* Subroutines of `comptypes'.  */
  509.  
  510. /* Return 1 if two function types F1 and F2 are compatible.
  511.    If either type specifies no argument types,
  512.    the other must specify a fixed number of self-promoting arg types.
  513.    Otherwise, if one type specifies only the number of arguments, 
  514.    the other must specify that number of self-promoting arg types.
  515.    Otherwise, the argument types must match.  */
  516.  
  517. static int
  518. function_types_compatible_p (f1, f2)
  519.      tree f1, f2;
  520. {
  521.   tree args1, args2;
  522.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  523.   int val = 1;
  524.   int val1;
  525.  
  526.   if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
  527.     || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
  528.     return 0;
  529.  
  530.   args1 = TYPE_ARG_TYPES (f1);
  531.   args2 = TYPE_ARG_TYPES (f2);
  532.  
  533.   /* An unspecified parmlist matches any specified parmlist
  534.      whose argument types don't need default promotions.  */
  535.  
  536.   if (args1 == 0)
  537.     {
  538.       if (!self_promoting_args_p (args2))
  539.     return 0;
  540.       /* If one of these types comes from a non-prototype fn definition,
  541.      compare that with the other type's arglist.
  542.      If they don't match, ask for a warning (but no error).  */
  543.       if (TYPE_ACTUAL_ARG_TYPES (f1)
  544.       && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
  545.     val = 2;
  546.       return val;
  547.     }
  548.   if (args2 == 0)
  549.     {
  550.       if (!self_promoting_args_p (args1))
  551.     return 0;
  552.       if (TYPE_ACTUAL_ARG_TYPES (f2)
  553.       && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
  554.     val = 2;
  555.       return val;
  556.     }
  557.  
  558.   /* Both types have argument lists: compare them and propagate results.  */
  559.   val1 = type_lists_compatible_p (args1, args2);
  560.   return val1 != 1 ? val1 : val;
  561. }
  562.  
  563. /* Check two lists of types for compatibility,
  564.    returning 0 for incompatible, 1 for compatible,
  565.    or 2 for compatible with warning.  */
  566.  
  567. static int
  568. type_lists_compatible_p (args1, args2)
  569.      tree args1, args2;
  570. {
  571.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  572.   int val = 1;
  573.   int newval;
  574.  
  575.   while (1)
  576.     {
  577.       if (args1 == 0 && args2 == 0)
  578.     return val;
  579.       /* If one list is shorter than the other,
  580.      they fail to match.  */
  581.       if (args1 == 0 || args2 == 0)
  582.     return 0;
  583.       /* A null pointer instead of a type
  584.      means there is supposed to be an argument
  585.      but nothing is specified about what type it has.
  586.      So match anything that self-promotes.  */
  587.       if (TREE_VALUE (args1) == 0)
  588.     {
  589.       if (! self_promoting_type_p (TREE_VALUE (args2)))
  590.         return 0;
  591.     }
  592.       else if (TREE_VALUE (args2) == 0)
  593.     {
  594.       if (! self_promoting_type_p (TREE_VALUE (args1)))
  595.         return 0;
  596.     }
  597.       else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
  598.     {
  599.       /* Allow  wait (union {union wait *u; int *i} *)
  600.          and  wait (union wait *)  to be compatible.  */
  601.       if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
  602.           && TYPE_NAME (TREE_VALUE (args1)) == 0
  603.           && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
  604.           && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
  605.                      TYPE_SIZE (TREE_VALUE (args2))))
  606.         {
  607.           tree memb;
  608.           for (memb = TYPE_FIELDS (TREE_VALUE (args1));
  609.            memb; memb = TREE_CHAIN (memb))
  610.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
  611.           break;
  612.           if (memb == 0)
  613.         return 0;
  614.         }
  615.       else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
  616.            && TYPE_NAME (TREE_VALUE (args2)) == 0
  617.            && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
  618.            && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
  619.                       TYPE_SIZE (TREE_VALUE (args1))))
  620.         {
  621.           tree memb;
  622.           for (memb = TYPE_FIELDS (TREE_VALUE (args2));
  623.            memb; memb = TREE_CHAIN (memb))
  624.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
  625.           break;
  626.           if (memb == 0)
  627.         return 0;
  628.         }
  629.       else
  630.         return 0;
  631.     }
  632.  
  633.       /* comptypes said ok, but record if it said to warn.  */
  634.       if (newval > val)
  635.     val = newval;
  636.  
  637.       args1 = TREE_CHAIN (args1);
  638.       args2 = TREE_CHAIN (args2);
  639.     }
  640. }
  641.  
  642. /* Return 1 if PARMS specifies a fixed number of parameters
  643.    and none of their types is affected by default promotions.  */
  644.  
  645. int
  646. self_promoting_args_p (parms)
  647.      tree parms;
  648. {
  649.   register tree t;
  650.   for (t = parms; t; t = TREE_CHAIN (t))
  651.     {
  652.       register tree type = TREE_VALUE (t);
  653.  
  654.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  655.     return 0;
  656.  
  657.       if (type == 0)
  658.     return 0;
  659.  
  660.       if (TYPE_MAIN_VARIANT (type) == float_type_node)
  661.     return 0;
  662.  
  663.       if (C_PROMOTING_INTEGER_TYPE_P (type))
  664.     return 0;
  665.     }
  666.   return 1;
  667. }
  668.  
  669. /* Return 1 if TYPE is not affected by default promotions.  */
  670.  
  671. static int
  672. self_promoting_type_p (type)
  673.      tree type;
  674. {
  675.   if (TYPE_MAIN_VARIANT (type) == float_type_node)
  676.     return 0;
  677.  
  678.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  679.     return 0;
  680.  
  681.   return 1;
  682. }
  683.  
  684. /* Return an unsigned type the same as TYPE in other respects.  */
  685.  
  686. tree
  687. unsigned_type (type)
  688.      tree type;
  689. {
  690.   tree type1 = TYPE_MAIN_VARIANT (type);
  691.   if (type1 == signed_char_type_node || type1 == char_type_node)
  692.     return unsigned_char_type_node;
  693.   if (type1 == integer_type_node)
  694.     return unsigned_type_node;
  695.   if (type1 == short_integer_type_node)
  696.     return short_unsigned_type_node;
  697.   if (type1 == long_integer_type_node)
  698.     return long_unsigned_type_node;
  699.   if (type1 == long_long_integer_type_node)
  700.     return long_long_unsigned_type_node;
  701.   return type;
  702. }
  703.  
  704. /* Return a signed type the same as TYPE in other respects.  */
  705.  
  706. tree
  707. signed_type (type)
  708.      tree type;
  709. {
  710.   tree type1 = TYPE_MAIN_VARIANT (type);
  711.   if (type1 == unsigned_char_type_node || type1 == char_type_node)
  712.     return signed_char_type_node;
  713.   if (type1 == unsigned_type_node)
  714.     return integer_type_node;
  715.   if (type1 == short_unsigned_type_node)
  716.     return short_integer_type_node;
  717.   if (type1 == long_unsigned_type_node)
  718.     return long_integer_type_node;
  719.   if (type1 == long_long_unsigned_type_node)
  720.     return long_long_integer_type_node;
  721.   return type;
  722. }
  723.  
  724. /* Return a type the same as TYPE except unsigned or
  725.    signed according to UNSIGNEDP.  */
  726.  
  727. tree
  728. signed_or_unsigned_type (unsignedp, type)
  729.      int unsignedp;
  730.      tree type;
  731. {
  732.   if (TREE_CODE (type) != INTEGER_TYPE)
  733.     return type;
  734.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  735.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  736.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  737.     return unsignedp ? unsigned_type_node : integer_type_node;
  738.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  739.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  740.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  741.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  742.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  743.     return (unsignedp ? long_long_unsigned_type_node
  744.         : long_long_integer_type_node);
  745.   return type;
  746. }
  747.  
  748. /* Compute the value of the `sizeof' operator.  */
  749.  
  750. tree
  751. c_sizeof (type)
  752.      tree type;
  753. {
  754.   enum tree_code code = TREE_CODE (type);
  755.   tree t;
  756.  
  757.   if (code == FUNCTION_TYPE)
  758.     {
  759.       if (pedantic || warn_pointer_arith)
  760.     pedwarn ("sizeof applied to a function type");
  761.       return size_int (1);
  762.     }
  763.   if (code == VOID_TYPE)
  764.     {
  765.       if (pedantic || warn_pointer_arith)
  766.     pedwarn ("sizeof applied to a void type");
  767.       return size_int (1);
  768.     }
  769.   if (code == ERROR_MARK)
  770.     return size_int (1);
  771.   if (TYPE_SIZE (type) == 0)
  772.     {
  773.       error ("sizeof applied to an incomplete type");
  774.       return size_int (0);
  775.     }
  776.  
  777.   /* Convert in case a char is more than one unit.  */
  778.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  779.           size_int (TYPE_PRECISION (char_type_node)));
  780.   /* size_binop does not put the constant in range, so do it now.  */
  781.   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
  782.     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
  783.   return t;
  784. }
  785.  
  786. tree
  787. c_sizeof_nowarn (type)
  788.      tree type;
  789. {
  790.   enum tree_code code = TREE_CODE (type);
  791.   tree t;
  792.  
  793.   if (code == FUNCTION_TYPE
  794.       || code == VOID_TYPE
  795.       || code == ERROR_MARK)
  796.     return size_int (1);
  797.   if (TYPE_SIZE (type) == 0)
  798.     return size_int (0);
  799.  
  800.   /* Convert in case a char is more than one unit.  */
  801.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  802.           size_int (TYPE_PRECISION (char_type_node)));
  803.   force_fit_type (t, 0);
  804.   return t;
  805. }
  806.  
  807. /* Compute the size to increment a pointer by.  */
  808.  
  809. tree
  810. c_size_in_bytes (type)
  811.      tree type;
  812. {
  813.   enum tree_code code = TREE_CODE (type);
  814.   tree t;
  815.  
  816.   if (code == FUNCTION_TYPE)
  817.     return size_int (1);
  818.   if (code == VOID_TYPE)
  819.     return size_int (1);
  820.   if (code == ERROR_MARK)
  821.     return size_int (1);
  822.   if (TYPE_SIZE (type) == 0)
  823.     {
  824.       error ("arithmetic on pointer to an incomplete type");
  825.       return size_int (1);
  826.     }
  827.  
  828.   /* Convert in case a char is more than one unit.  */
  829.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  830.              size_int (BITS_PER_UNIT));
  831.   force_fit_type (t, 0);
  832.   return t;
  833. }
  834.  
  835. /* Implement the __alignof keyword: Return the minimum required
  836.    alignment of TYPE, measured in bytes.  */
  837.  
  838. tree
  839. c_alignof (type)
  840.      tree type;
  841. {
  842.   enum tree_code code = TREE_CODE (type);
  843.  
  844.   if (code == FUNCTION_TYPE)
  845.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  846.  
  847.   if (code == VOID_TYPE || code == ERROR_MARK)
  848.     return size_int (1);
  849.  
  850.   if (TYPE_SIZE (type) == 0)
  851.     {
  852.       warning ("__alignof applied to an incomplete type");
  853.       return size_int (1);
  854.     }
  855.  
  856.   return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  857. }
  858.  
  859. /* Implement the __alignof keyword: Return the minimum required
  860.    alignment of EXPR, measured in bytes.  For VAR_DECL's and
  861.    FIELD_DECL's return DECL_ALIGN (which can be set from an
  862.    "aligned" __attribute__ specification).  */
  863.  
  864. tree
  865. c_alignof_expr (expr)
  866.      tree expr;
  867. {
  868.   if (TREE_CODE (expr) == VAR_DECL)
  869.     return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
  870.  
  871.   if (TREE_CODE (expr) == COMPONENT_REF
  872.       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
  873.     {
  874.       error ("`__alignof' applied to a bit-field");
  875.       return size_int (1);
  876.     }
  877.   else if (TREE_CODE (expr) == COMPONENT_REF
  878.       && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
  879.     return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
  880.  
  881.   if (TREE_CODE (expr) == INDIRECT_REF)
  882.     {
  883.       tree t = TREE_OPERAND (expr, 0);
  884.       tree best = t;
  885.       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  886.  
  887.       while (TREE_CODE (t) == NOP_EXPR
  888.           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  889.     {
  890.       int thisalign;
  891.  
  892.       t = TREE_OPERAND (t, 0);
  893.       thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  894.       if (thisalign > bestalign)
  895.         best = t, bestalign = thisalign;
  896.     }
  897.       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
  898.     }
  899.   else
  900.     return c_alignof (TREE_TYPE (expr));
  901. }
  902. /* Return either DECL or its known constant value (if it has one).  */
  903.  
  904. static tree
  905. decl_constant_value (decl)
  906.      tree decl;
  907. {
  908.   if (! TREE_PUBLIC (decl)
  909.       /* Don't change a variable array bound or initial value to a constant
  910.      in a place where a variable is invalid.  */
  911.       && current_function_decl != 0
  912.       && ! pedantic
  913.       && ! TREE_THIS_VOLATILE (decl)
  914.       && DECL_INITIAL (decl) != 0
  915.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  916.       /* This is invalid if initial value is not constant.
  917.      If it has either a function call, a memory reference,
  918.      or a variable, then re-evaluating it could give different results.  */
  919.       && TREE_CONSTANT (DECL_INITIAL (decl))
  920.       /* Check for cases where this is sub-optimal, even though valid.  */
  921.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  922.       && DECL_MODE (decl) != BLKmode)
  923.     return DECL_INITIAL (decl);
  924.   return decl;
  925. }
  926.  
  927. /* Perform default promotions for C data used in expressions.
  928.    Arrays and functions are converted to pointers;
  929.    enumeral types or short or char, to int.
  930.    In addition, manifest constants symbols are replaced by their values.  */
  931.  
  932. tree
  933. default_conversion (exp)
  934.      tree exp;
  935. {
  936.   register tree type = TREE_TYPE (exp);
  937.   register enum tree_code code = TREE_CODE (type);
  938.  
  939.   /* Constants can be used directly unless they're not loadable.  */
  940.   if (TREE_CODE (exp) == CONST_DECL)
  941.     exp = DECL_INITIAL (exp);
  942.   /* Replace a nonvolatile const static variable with its value.  */
  943.   else if (optimize
  944.        && TREE_CODE (exp) == VAR_DECL
  945.        && TREE_READONLY (exp)
  946.        /* But not for iterators!  */
  947.        && !ITERATOR_P (exp)
  948.        /* And not arrays used as addresses */
  949.        && code != ARRAY_TYPE
  950.        && DECL_MODE (exp) != BLKmode)
  951.     {
  952.       exp = decl_constant_value (exp);
  953.       type = TREE_TYPE (exp);
  954.     }
  955.  
  956.   /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
  957.      an lvalue.  */
  958.   /* Do not use STRIP_NOPS here!  It will remove conversions from pointer
  959.      to integer and cause infinite recursion.  */
  960.   while (TREE_CODE (exp) == NON_LVALUE_EXPR
  961.      || (TREE_CODE (exp) == NOP_EXPR
  962.          && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
  963.     exp = TREE_OPERAND (exp, 0);
  964.  
  965.   /* Normally convert enums to int,
  966.      but convert wide enums to something wider.  */
  967.   if (code == ENUMERAL_TYPE)
  968.     {
  969.       type = type_for_size (MAX (TYPE_PRECISION (type),
  970.                  TYPE_PRECISION (integer_type_node)),
  971.                 ((flag_traditional
  972.                   || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
  973.                  && TREE_UNSIGNED (type)));
  974.       return convert (type, exp);
  975.     }
  976.  
  977.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  978.     {
  979.       /* Traditionally, unsignedness is preserved in default promotions.
  980.          Also preserve unsignedness if not really getting any wider.  */
  981.       if (TREE_UNSIGNED (type)
  982.       && (flag_traditional
  983.           || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
  984.     return convert (unsigned_type_node, exp);
  985.       return convert (integer_type_node, exp);
  986.     }
  987.   if (flag_traditional && !flag_allow_single_precision
  988.       && TYPE_MAIN_VARIANT (type) == float_type_node)
  989.     return convert (double_type_node, exp);
  990.   if (code == VOID_TYPE)
  991.     {
  992.       error ("void value not ignored as it ought to be");
  993.       return error_mark_node;
  994.     }
  995.   if (code == FUNCTION_TYPE)
  996.     {
  997.       return build_unary_op (ADDR_EXPR, exp, 0);
  998.     }
  999.   if (code == ARRAY_TYPE)
  1000.     {
  1001.       register tree adr;
  1002.       tree restype = TREE_TYPE (type);
  1003.       tree ptrtype;
  1004.       int constp = 0;
  1005.       int volatilep = 0;
  1006.  
  1007.       if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
  1008.       || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
  1009.     {
  1010.       constp = TREE_READONLY (exp);
  1011.       volatilep = TREE_THIS_VOLATILE (exp);
  1012.     }
  1013.  
  1014.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
  1015.       || constp || volatilep)
  1016.     restype = c_build_type_variant (restype,
  1017.                     TYPE_READONLY (type) || constp,
  1018.                     TYPE_VOLATILE (type) || volatilep);
  1019.  
  1020.       if (TREE_CODE (exp) == INDIRECT_REF)
  1021.     return convert (TYPE_POINTER_TO (restype),
  1022.             TREE_OPERAND (exp, 0));
  1023.  
  1024.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  1025.     {
  1026.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  1027.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  1028.             TREE_OPERAND (exp, 0), op1);
  1029.     }
  1030.  
  1031.       if (!lvalue_p (exp)
  1032.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  1033.     {
  1034.       error ("invalid use of non-lvalue array");
  1035.       return error_mark_node;
  1036.     }
  1037.  
  1038.       ptrtype = build_pointer_type (restype);
  1039.  
  1040.       if (TREE_CODE (exp) == VAR_DECL)
  1041.     {
  1042.       /* ??? This is not really quite correct
  1043.          in that the type of the operand of ADDR_EXPR
  1044.          is not the target type of the type of the ADDR_EXPR itself.
  1045.          Question is, can this lossage be avoided?  */
  1046.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  1047.       if (mark_addressable (exp) == 0)
  1048.         return error_mark_node;
  1049.       TREE_CONSTANT (adr) = staticp (exp);
  1050.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  1051.       return adr;
  1052.     }
  1053.       /* This way is better for a COMPONENT_REF since it can
  1054.      simplify the offset for a component.  */
  1055.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  1056.       return convert (ptrtype, adr);
  1057.     }
  1058.  
  1059.   return exp;
  1060. }
  1061.  
  1062. /* Look up component name in the structure type definition.
  1063.  
  1064.    If this component name is found indirectly within an anonymous union,
  1065.    store in *INDIRECT the component which directly contains
  1066.    that anonymous union.  Otherwise, set *INDIRECT to 0.  */
  1067.      
  1068. static tree
  1069. lookup_field (type, component, indirect)
  1070.      tree type, component;
  1071.      tree *indirect;
  1072. {
  1073.   tree field;
  1074.  
  1075.   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
  1076.      to the field elements.  Use a binary search on this array to quickly
  1077.      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
  1078.      will always be set for structures which have many elements.  */
  1079.  
  1080.   if (TYPE_LANG_SPECIFIC (type))
  1081.     {
  1082.       int bot, top, half;
  1083.       tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
  1084.  
  1085.       field = TYPE_FIELDS (type);
  1086.       bot = 0;
  1087.       top = TYPE_LANG_SPECIFIC (type)->len;
  1088.       while (top - bot > 1)
  1089.     {
  1090.       HOST_WIDE_INT cmp;
  1091.  
  1092.       half = (top - bot + 1) >> 1;
  1093.       field = field_array[bot+half];
  1094.  
  1095.       if (DECL_NAME (field) == NULL_TREE)
  1096.         {
  1097.           /* Step through all anon unions in linear fashion.  */
  1098.           while (DECL_NAME (field_array[bot]) == NULL_TREE)
  1099.         {
  1100.           tree anon, junk;
  1101.  
  1102.           field = field_array[bot++];
  1103.           anon = lookup_field (TREE_TYPE (field), component, &junk);
  1104.           if (anon != NULL_TREE)
  1105.             {
  1106.               *indirect = field;
  1107.               return anon;
  1108.             }
  1109.         }
  1110.  
  1111.           /* Entire record is only anon unions.  */
  1112.           if (bot > top)
  1113.         return NULL_TREE;
  1114.  
  1115.           /* Restart the binary search, with new lower bound.  */
  1116.           continue;
  1117.         }
  1118.  
  1119.       cmp = (HOST_WIDE_INT) DECL_NAME (field) - (HOST_WIDE_INT) component;
  1120.       if (cmp == 0)
  1121.         break;
  1122.       if (cmp < 0)
  1123.         bot += half;
  1124.       else
  1125.         top = bot + half;
  1126.     }
  1127.  
  1128.       if (DECL_NAME (field_array[bot]) == component)
  1129.     field = field_array[bot];
  1130.       else if (DECL_NAME (field) != component)
  1131.     field = 0;
  1132.     }
  1133.   else
  1134.     {
  1135.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  1136.     {
  1137.       if (DECL_NAME (field) == NULL_TREE)
  1138.         {
  1139.           tree junk;
  1140.           tree anon = lookup_field (TREE_TYPE (field), component, &junk);
  1141.           if (anon != NULL_TREE)
  1142.         {
  1143.           *indirect = field;
  1144.           return anon;
  1145.         }
  1146.         }
  1147.  
  1148.       if (DECL_NAME (field) == component)
  1149.         break;
  1150.     }
  1151.     }
  1152.  
  1153.   *indirect = NULL_TREE;
  1154.   return field;
  1155. }
  1156.  
  1157. /* Make an expression to refer to the COMPONENT field of
  1158.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  1159.  
  1160. tree
  1161. build_component_ref (datum, component)
  1162.      tree datum, component;
  1163. {
  1164.   register tree type = TREE_TYPE (datum);
  1165.   register enum tree_code code = TREE_CODE (type);
  1166.   register tree field = NULL;
  1167.   register tree ref;
  1168.  
  1169.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
  1170.      unless we are not to support things not strictly ANSI.  */
  1171.   switch (TREE_CODE (datum))
  1172.     {
  1173.     case COMPOUND_EXPR:
  1174.       {
  1175.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
  1176.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  1177.               TREE_OPERAND (datum, 0), value);
  1178.       }
  1179.     case COND_EXPR:
  1180.       return build_conditional_expr
  1181.     (TREE_OPERAND (datum, 0),
  1182.      build_component_ref (TREE_OPERAND (datum, 1), component),
  1183.      build_component_ref (TREE_OPERAND (datum, 2), component));
  1184.     }
  1185.  
  1186.   /* See if there is a field or component with name COMPONENT.  */
  1187.  
  1188.   if (code == RECORD_TYPE || code == UNION_TYPE)
  1189.     {
  1190.       tree indirect = 0;
  1191.  
  1192.       if (TYPE_SIZE (type) == 0)
  1193.     {
  1194.       incomplete_type_error (NULL_TREE, type);
  1195.       return error_mark_node;
  1196.     }
  1197.  
  1198.       field = lookup_field (type, component, &indirect);
  1199.  
  1200.       if (!field)
  1201.     {
  1202.       error (code == RECORD_TYPE
  1203.          ? "structure has no member named `%s'"
  1204.          : "union has no member named `%s'",
  1205.          IDENTIFIER_POINTER (component));
  1206.       return error_mark_node;
  1207.     }
  1208.       if (TREE_TYPE (field) == error_mark_node)
  1209.     return error_mark_node;
  1210.  
  1211.       /* If FIELD was found buried within an anonymous union,
  1212.      make one COMPONENT_REF to get that anonymous union,
  1213.      then fall thru to make a second COMPONENT_REF to get FIELD.  */
  1214.       if (indirect != 0)
  1215.     {
  1216.       ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
  1217.       if (TREE_READONLY (datum) || TREE_READONLY (indirect))
  1218.         TREE_READONLY (ref) = 1;
  1219.       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
  1220.         TREE_THIS_VOLATILE (ref) = 1;
  1221.       datum = ref;
  1222.     }
  1223.  
  1224.       ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  1225.  
  1226.       if (TREE_READONLY (datum) || TREE_READONLY (field))
  1227.     TREE_READONLY (ref) = 1;
  1228.       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1229.     TREE_THIS_VOLATILE (ref) = 1;
  1230.  
  1231.       return ref;
  1232.     }
  1233.   else if (code != ERROR_MARK)
  1234.     error ("request for member `%s' in something not a structure or union",
  1235.         IDENTIFIER_POINTER (component));
  1236.  
  1237.   return error_mark_node;
  1238. }
  1239.  
  1240. /* Given an expression PTR for a pointer, return an expression
  1241.    for the value pointed to.
  1242.    ERRORSTRING is the name of the operator to appear in error messages.  */
  1243.  
  1244. tree
  1245. build_indirect_ref (ptr, errorstring)
  1246.      tree ptr;
  1247.      char *errorstring;
  1248. {
  1249.   register tree pointer = default_conversion (ptr);
  1250.   register tree type = TREE_TYPE (pointer);
  1251.  
  1252.   if (TREE_CODE (type) == POINTER_TYPE)
  1253.     {
  1254.       if (TREE_CODE (pointer) == ADDR_EXPR
  1255.       && !flag_volatile
  1256.       && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  1257.           == TREE_TYPE (type)))
  1258.     return TREE_OPERAND (pointer, 0);
  1259.       else
  1260.     {
  1261.       tree t = TREE_TYPE (type);
  1262.       register tree ref = build1 (INDIRECT_REF,
  1263.                       TYPE_MAIN_VARIANT (t), pointer);
  1264.  
  1265.       if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
  1266.         {
  1267. #ifdef NeXT
  1268.           require_complete_type (type);
  1269. #endif
  1270.           error ("dereferencing pointer to incomplete type");
  1271.           return error_mark_node;
  1272.         }
  1273.       if (TREE_CODE (t) == VOID_TYPE)
  1274.         warning ("dereferencing `void *' pointer");
  1275.  
  1276.       /* We *must* set TREE_READONLY when dereferencing a pointer to const,
  1277.          so that we get the proper error message if the result is used
  1278.          to assign to.  Also, &* is supposed to be a no-op.
  1279.          And ANSI C seems to specify that the type of the result
  1280.          should be the const type.  */
  1281.       /* A de-reference of a pointer to const is not a const.  It is valid
  1282.          to change it via some other pointer.  */
  1283.       TREE_READONLY (ref) = TYPE_READONLY (t);
  1284.       TREE_SIDE_EFFECTS (ref)
  1285.         = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
  1286.       TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  1287.       return ref;
  1288.     }
  1289.     }
  1290.   else if (TREE_CODE (pointer) != ERROR_MARK)
  1291.     error ("invalid type argument of `%s'", errorstring);
  1292.   return error_mark_node;
  1293. }
  1294.  
  1295. /* This handles expressions of the form "a[i]", which denotes
  1296.    an array reference.
  1297.  
  1298.    This is logically equivalent in C to *(a+i), but we may do it differently.
  1299.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1300.    This avoids forcing the array out of registers, and can work on
  1301.    arrays that are not lvalues (for example, members of structures returned
  1302.    by functions).  */
  1303.  
  1304. tree
  1305. build_array_ref (array, index)
  1306.      tree array, index;
  1307. {
  1308.   if (index == 0)
  1309.     {
  1310.       error ("subscript missing in array reference");
  1311.       return error_mark_node;
  1312.     }
  1313.  
  1314.   if (TREE_TYPE (array) == error_mark_node
  1315.       || TREE_TYPE (index) == error_mark_node)
  1316.     return error_mark_node;
  1317.  
  1318.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1319.       && TREE_CODE (array) != INDIRECT_REF)
  1320.     {
  1321.       tree rval, type;
  1322.  
  1323.       /* Subscripting with type char is likely to lose
  1324.      on a machine where chars are signed.
  1325.      So warn on any machine, but optionally.
  1326.      Don't warn for unsigned char since that type is safe.
  1327.      Don't warn for signed char because anyone who uses that
  1328.      must have done so deliberately.  */
  1329.       if (warn_char_subscripts
  1330.       && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
  1331.     warning ("array subscript has type `char'");
  1332.  
  1333.       /* Apply default promotions *after* noticing character types.  */
  1334.       index = default_conversion (index);
  1335.  
  1336.       /* Require integer *after* promotion, for sake of enums.  */
  1337.       if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  1338.     {
  1339.       error ("array subscript is not an integer");
  1340.       return error_mark_node;
  1341.     }
  1342.  
  1343.       /* An array that is indexed by a non-constant
  1344.      cannot be stored in a register; we must be able to do
  1345.      address arithmetic on its address.
  1346.      Likewise an array of elements of variable size.  */
  1347.       if (TREE_CODE (index) != INTEGER_CST
  1348.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  1349.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  1350.     {
  1351.       if (mark_addressable (array) == 0)
  1352.         return error_mark_node;
  1353.     }
  1354.       /* An array that is indexed by a constant value which is not within
  1355.      the array bounds cannot be stored in a register either; because we
  1356.      would get a crash in store_bit_field/extract_bit_field when trying
  1357.      to access a non-existent part of the register.  */
  1358.       if (TREE_CODE (index) == INTEGER_CST
  1359.       && TYPE_VALUES (TREE_TYPE (array))
  1360.       && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
  1361.     {
  1362.       if (mark_addressable (array) == 0)
  1363.         return error_mark_node;
  1364.     }
  1365.  
  1366.       if (pedantic && !lvalue_p (array))
  1367.     {
  1368.       if (DECL_REGISTER (array))
  1369.         pedwarn ("ANSI C forbids subscripting `register' array");
  1370.       else
  1371.         pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1372.     }
  1373.  
  1374.       if (pedantic)
  1375.     {
  1376.       tree foo = array;
  1377.       while (TREE_CODE (foo) == COMPONENT_REF)
  1378.         foo = TREE_OPERAND (foo, 0);
  1379.       if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
  1380.         pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1381.     }
  1382.  
  1383.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  1384.       rval = build (ARRAY_REF, type, array, index);
  1385.       /* Array ref is const/volatile if the array elements are
  1386.          or if the array is.  */
  1387.       TREE_READONLY (rval)
  1388.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  1389.         | TREE_READONLY (array));
  1390.       TREE_SIDE_EFFECTS (rval)
  1391.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1392.         | TREE_SIDE_EFFECTS (array));
  1393.       TREE_THIS_VOLATILE (rval)
  1394.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1395.         /* This was added by rms on 16 Nov 91.
  1396.            It fixes  vol struct foo *a;  a->elts[1] 
  1397.            in an inline function.
  1398.            Hope it doesn't break something else.  */
  1399.         | TREE_THIS_VOLATILE (array));
  1400.       return require_complete_type (fold (rval));
  1401.     }
  1402.  
  1403.   {
  1404.     tree ar = default_conversion (array);
  1405.     tree ind = default_conversion (index);
  1406.  
  1407.     /* Put the integer in IND to simplify error checking.  */
  1408.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  1409.       {
  1410.     tree temp = ar;
  1411.     ar = ind;
  1412.     ind = temp;
  1413.       }
  1414.  
  1415.     if (ar == error_mark_node)
  1416.       return ar;
  1417.  
  1418.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  1419.       {
  1420.     error ("subscripted value is neither array nor pointer");
  1421.     return error_mark_node;
  1422.       }
  1423.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  1424.       {
  1425.     error ("array subscript is not an integer");
  1426.     return error_mark_node;
  1427.       }
  1428.  
  1429.     return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
  1430.                    "array indexing");
  1431.   }
  1432. }
  1433.  
  1434. /* Build a function call to function FUNCTION with parameters PARAMS.
  1435.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  1436.    TREE_VALUE of each node is a parameter-expression.
  1437.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  1438.  
  1439. tree
  1440. build_function_call (function, params)
  1441.      tree function, params;
  1442. {
  1443.   register tree fntype, fundecl = 0;
  1444.   register tree coerced_params;
  1445.   tree name = NULL_TREE, assembler_name = NULL_TREE;
  1446.  
  1447.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  1448.   STRIP_TYPE_NOPS (function);
  1449.  
  1450.   /* Convert anything with function type to a pointer-to-function.  */
  1451.   if (TREE_CODE (function) == FUNCTION_DECL)
  1452.     {
  1453.       name = DECL_NAME (function);
  1454.       assembler_name = DECL_ASSEMBLER_NAME (function);
  1455.  
  1456.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  1457.      (because calling an inline function does not mean the function
  1458.      needs to be separately compiled).  */
  1459.       fntype = build_type_variant (TREE_TYPE (function),
  1460.                    TREE_READONLY (function),
  1461.                    TREE_THIS_VOLATILE (function));
  1462.       fundecl = function;
  1463.       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
  1464.     }
  1465.   else
  1466.     function = default_conversion (function);
  1467.  
  1468.   fntype = TREE_TYPE (function);
  1469.  
  1470.   if (TREE_CODE (fntype) == ERROR_MARK)
  1471.     return error_mark_node;
  1472.  
  1473.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  1474.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  1475.     {
  1476.       error ("called object is not a function");
  1477.       return error_mark_node;
  1478.     }
  1479.  
  1480.   /* fntype now gets the type of function pointed to.  */
  1481.   fntype = TREE_TYPE (fntype);
  1482.  
  1483.   /* Convert the parameters to the types declared in the
  1484.      function prototype, or apply default promotions.  */
  1485.  
  1486.   coerced_params
  1487.     = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
  1488.  
  1489.   /* Check for errors in format strings.  */
  1490.  
  1491.   if (warn_format && (name || assembler_name))
  1492.     check_function_format (name, assembler_name, coerced_params);
  1493.  
  1494.   /* Recognize certain built-in functions so we can make tree-codes
  1495.      other than CALL_EXPR.  We do this when it enables fold-const.c
  1496.      to do something useful.  */
  1497.  
  1498.   if (TREE_CODE (function) == ADDR_EXPR
  1499.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  1500.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  1501.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  1502.       {
  1503.       case BUILT_IN_ABS:
  1504.       case BUILT_IN_LABS:
  1505.       case BUILT_IN_FABS:
  1506.     if (coerced_params == 0)
  1507.       return integer_zero_node;
  1508.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  1509.       }
  1510.  
  1511.   {
  1512.     register tree result
  1513.       = build (CALL_EXPR, TREE_TYPE (fntype),
  1514.            function, coerced_params, NULL_TREE);
  1515.  
  1516.     TREE_SIDE_EFFECTS (result) = 1;
  1517.     if (TREE_TYPE (result) == void_type_node)
  1518.       return result;
  1519.     return require_complete_type (result);
  1520.   }
  1521. }
  1522.  
  1523. /* Convert the argument expressions in the list VALUES
  1524.    to the types in the list TYPELIST.  The result is a list of converted
  1525.    argument expressions.
  1526.  
  1527.    If TYPELIST is exhausted, or when an element has NULL as its type,
  1528.    perform the default conversions.
  1529.  
  1530.    PARMLIST is the chain of parm decls for the function being called.
  1531.    It may be 0, if that info is not available.
  1532.    It is used only for generating error messages.
  1533.  
  1534.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  1535.  
  1536.    This is also where warnings about wrong number of args are generated.
  1537.  
  1538.    Both VALUES and the returned value are chains of TREE_LIST nodes
  1539.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  1540.  
  1541. static tree
  1542. convert_arguments (typelist, values, name, fundecl)
  1543.      tree typelist, values, name, fundecl;
  1544. {
  1545.   register tree typetail, valtail;
  1546.   register tree result = NULL;
  1547.   int parmnum;
  1548.  
  1549.   /* Scan the given expressions and types, producing individual
  1550.      converted arguments and pushing them on RESULT in reverse order.  */
  1551.  
  1552.   for (valtail = values, typetail = typelist, parmnum = 0;
  1553.        valtail;
  1554.        valtail = TREE_CHAIN (valtail), parmnum++)
  1555.     {
  1556.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  1557.       register tree val = TREE_VALUE (valtail);
  1558.  
  1559.       if (type == void_type_node)
  1560.     {
  1561.       if (name)
  1562.         error ("too many arguments to function `%s'",
  1563.            IDENTIFIER_POINTER (name));
  1564.       else
  1565.         error ("too many arguments to function");
  1566.       break;
  1567.     }
  1568.  
  1569.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  1570.       /* Do not use STRIP_NOPS here!  We do not want an enumerator with value 0
  1571.      to convert automatically to a pointer.  */
  1572.       if (TREE_CODE (val) == NON_LVALUE_EXPR)
  1573.     val = TREE_OPERAND (val, 0);
  1574.  
  1575.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  1576.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  1577.     val = default_conversion (val);
  1578.  
  1579.       val = require_complete_type (val);
  1580.  
  1581.       if (type != 0)
  1582.     {
  1583.       /* Formal parm type is specified by a function prototype.  */
  1584.       tree parmval;
  1585.  
  1586.       if (TYPE_SIZE (type) == 0)
  1587.         {
  1588.           error ("type of formal parameter %d is incomplete", parmnum + 1);
  1589.           parmval = val;
  1590.         }
  1591.       else
  1592.         {
  1593.           tree parmname;
  1594.           tree type0 = type;
  1595. #ifdef PROMOTE_PROTOTYPES
  1596.           /* Rather than truncating and then reextending,
  1597.          convert directly to int, if that's the type we will want.  */
  1598.           if (! flag_traditional
  1599.           && (TREE_CODE (type) == INTEGER_TYPE
  1600.               || TREE_CODE (type) == ENUMERAL_TYPE)
  1601.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1602.         type = integer_type_node;
  1603. #endif
  1604.  
  1605. #if 0 /* This turns out not to win--there's no way to write a prototype
  1606.      for a function whose arg type is a union with no tag.  */
  1607.           /* Nameless union automatically casts the types it contains.  */
  1608.           if (TREE_CODE (type) == UNION_TYPE && TYPE_NAME (type) == 0)
  1609.         {
  1610.           tree field;
  1611.  
  1612.           for (field = TYPE_FIELDS (type); field;
  1613.                field = TREE_CHAIN (field))
  1614.             if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
  1615.                    TYPE_MAIN_VARIANT (TREE_TYPE (val))))
  1616.               break;
  1617.  
  1618.           if (field)
  1619.             val = build1 (CONVERT_EXPR, type, val);
  1620.         }
  1621. #endif
  1622.  
  1623.           /* Optionally warn about conversions that
  1624.          differ from the default conversions.  */
  1625.           if (warn_conversion)
  1626.         {
  1627.           int formal_prec = TYPE_PRECISION (type);
  1628.  
  1629.           if (TREE_CODE (type) != REAL_TYPE
  1630.               && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1631.             warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
  1632.           else if (TREE_CODE (type) == REAL_TYPE
  1633.               && TREE_CODE (TREE_TYPE (val)) != REAL_TYPE)
  1634.             warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
  1635.           else if (TREE_CODE (type) == REAL_TYPE
  1636.                && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1637.             {
  1638.               /* Warn if any argument is passed as `float',
  1639.              since without a prototype it would be `double'.  */
  1640.               if (formal_prec == TYPE_PRECISION (float_type_node))
  1641.             warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
  1642.             }
  1643.           /* Detect integer changing in width or signedness.  */
  1644.           else if ((TREE_CODE (type) == INTEGER_TYPE
  1645.                 || TREE_CODE (type) == ENUMERAL_TYPE)
  1646.                && (TREE_CODE (TREE_TYPE (val)) == INTEGER_TYPE
  1647.                    || TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE))
  1648.             {
  1649.               tree would_have_been = default_conversion (val);
  1650.               tree type1 = TREE_TYPE (would_have_been);
  1651.  
  1652.               if (TREE_CODE (type) == ENUMERAL_TYPE
  1653.               && type == TREE_TYPE (val))
  1654.             /* No warning if function asks for enum
  1655.                and the actual arg is that enum type.  */
  1656.             ;
  1657.               else if (formal_prec != TYPE_PRECISION (type1))
  1658.             warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
  1659.               else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
  1660.             ;
  1661.               /* Don't complain if the formal parameter type
  1662.              is an enum, because we can't tell now whether
  1663.              the value was an enum--even the same enum.  */
  1664.               else if (TREE_CODE (type) == ENUMERAL_TYPE)
  1665.             ;
  1666.               else if (TREE_CODE (val) == INTEGER_CST
  1667.                    && int_fits_type_p (val, type))
  1668.             /* Change in signedness doesn't matter
  1669.                if a constant value is unaffected.  */
  1670.             ;
  1671.               /* Likewise for a constant in a NOP_EXPR.  */
  1672.               else if (TREE_CODE (val) == NOP_EXPR
  1673.                    && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
  1674.                    && int_fits_type_p (TREE_OPERAND (val, 0), type))
  1675.             ;
  1676. #if 0 /* We never get such tree structure here.  */
  1677.               else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
  1678.                    && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
  1679.                    && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
  1680.             /* Change in signedness doesn't matter
  1681.                if an enum value is unaffected.  */
  1682.             ;
  1683. #endif
  1684.               /* If the value is extended from a narrower
  1685.              unsigned type, it doesn't matter whether we
  1686.              pass it as signed or unsigned; the value
  1687.              certainly is the same either way.  */
  1688.               else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
  1689.                    && TREE_UNSIGNED (TREE_TYPE (val)))
  1690.             ;
  1691.               else if (TREE_UNSIGNED (type))
  1692.             warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
  1693.               else
  1694.             warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
  1695.             }
  1696.         }
  1697.  
  1698.           parmval = convert_for_assignment (type, val, 
  1699.                             (char *)0, /* arg passing  */
  1700.                         fundecl, name, parmnum + 1);
  1701.           
  1702. #ifdef PROMOTE_PROTOTYPES
  1703.           if ((TREE_CODE (type) == INTEGER_TYPE
  1704.            || TREE_CODE (type) == ENUMERAL_TYPE)
  1705.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1706.         parmval = default_conversion (parmval);
  1707. #endif
  1708.         }
  1709.       result = tree_cons (NULL_TREE, parmval, result);
  1710.     }
  1711.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  1712.                && (TYPE_PRECISION (TREE_TYPE (val))
  1713.                < TYPE_PRECISION (double_type_node)))
  1714.     /* Convert `float' to `double'.  */
  1715.     result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  1716.       else
  1717.     /* Convert `short' and `char' to full-size `int'.  */
  1718.     result = tree_cons (NULL_TREE, default_conversion (val), result);
  1719.  
  1720.       if (typetail)
  1721.     typetail = TREE_CHAIN (typetail);
  1722.     }
  1723.  
  1724.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  1725.     {
  1726.       if (name)
  1727.     error ("too few arguments to function `%s'",
  1728.            IDENTIFIER_POINTER (name));
  1729.       else
  1730.     error ("too few arguments to function");
  1731.     }
  1732.  
  1733.   return nreverse (result);
  1734. }
  1735.  
  1736. /* This is the entry point used by the parser
  1737.    for binary operators in the input.
  1738.    In addition to constructing the expression,
  1739.    we check for operands that were written with other binary operators
  1740.    in a way that is likely to confuse the user.  */
  1741.  
  1742. tree
  1743. parser_build_binary_op (code, arg1, arg2)
  1744.      enum tree_code code;
  1745.      tree arg1, arg2;
  1746. {
  1747.   tree result = build_binary_op (code, arg1, arg2, 1);
  1748.  
  1749.   char class;
  1750.   char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
  1751.   char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
  1752.   enum tree_code code1 = ERROR_MARK;
  1753.   enum tree_code code2 = ERROR_MARK;
  1754.  
  1755.   if (class1 == 'e' || class1 == '1'
  1756.       || class1 == '2' || class1 == '<')
  1757.     code1 = C_EXP_ORIGINAL_CODE (arg1);
  1758.   if (class2 == 'e' || class2 == '1'
  1759.       || class2 == '2' || class2 == '<')
  1760.     code2 = C_EXP_ORIGINAL_CODE (arg2);
  1761.  
  1762.   /* Check for cases such as x+y<<z which users are likely
  1763.      to misinterpret.  If parens are used, C_EXP_ORIGINAL_CODE
  1764.      is cleared to prevent these warnings.  */
  1765.   if (warn_parentheses)
  1766.     {
  1767.       if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
  1768.     {
  1769.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1770.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1771.         warning ("suggest parentheses around + or - inside shift");
  1772.     }
  1773.  
  1774.       if (code == TRUTH_ORIF_EXPR)
  1775.     {
  1776.       if (code1 == TRUTH_ANDIF_EXPR
  1777.           || code2 == TRUTH_ANDIF_EXPR)
  1778.         warning ("suggest parentheses around && within ||");
  1779.     }
  1780.  
  1781.       if (code == BIT_IOR_EXPR)
  1782.     {
  1783.       if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
  1784.           || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1785.           || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
  1786.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1787.         warning ("suggest parentheses around arithmetic in operand of |");
  1788.     }
  1789.  
  1790.       if (code == BIT_XOR_EXPR)
  1791.     {
  1792.       if (code1 == BIT_AND_EXPR
  1793.           || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1794.           || code2 == BIT_AND_EXPR
  1795.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1796.         warning ("suggest parentheses around arithmetic in operand of ^");
  1797.     }
  1798.  
  1799.       if (code == BIT_AND_EXPR)
  1800.     {
  1801.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1802.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1803.         warning ("suggest parentheses around + or - in operand of &");
  1804.     }
  1805.     }
  1806.  
  1807.   /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
  1808.   if (TREE_CODE_CLASS (code) == '<' && extra_warnings
  1809.       && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
  1810.     warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
  1811.  
  1812.   unsigned_conversion_warning (result, arg1);
  1813.   unsigned_conversion_warning (result, arg2);
  1814.   overflow_warning (result);
  1815.  
  1816.   class = TREE_CODE_CLASS (TREE_CODE (result));
  1817.  
  1818.   /* Record the code that was specified in the source,
  1819.      for the sake of warnings about confusing nesting.  */
  1820.   if (class == 'e' || class == '1'
  1821.       || class == '2' || class == '<')
  1822.     C_SET_EXP_ORIGINAL_CODE (result, code);
  1823.   else
  1824.     {
  1825.       int flag = TREE_CONSTANT (result);
  1826.       /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
  1827.      so that convert_for_assignment wouldn't strip it.
  1828.      That way, we got warnings for things like p = (1 - 1).
  1829.      But it turns out we should not get those warnings.  */
  1830.       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
  1831.       C_SET_EXP_ORIGINAL_CODE (result, code);
  1832.       TREE_CONSTANT (result) = flag;
  1833.     }
  1834.  
  1835.   return result;
  1836. }
  1837.  
  1838. /* Build a binary-operation expression without default conversions.
  1839.    CODE is the kind of expression to build.
  1840.    This function differs from `build' in several ways:
  1841.    the data type of the result is computed and recorded in it,
  1842.    warnings are generated if arg data types are invalid,
  1843.    special handling for addition and subtraction of pointers is known,
  1844.    and some optimization is done (operations on narrow ints
  1845.    are done in the narrower type when that gives the same result).
  1846.    Constant folding is also done before the result is returned.
  1847.  
  1848.    Note that the operands will never have enumeral types, or function
  1849.    or array types, because either they will have the default conversions
  1850.    performed or they have both just been converted to some other type in which
  1851.    the arithmetic is to be done.  */
  1852.  
  1853. tree
  1854. build_binary_op (code, orig_op0, orig_op1, convert_p)
  1855.      enum tree_code code;
  1856.      tree orig_op0, orig_op1;
  1857.      int convert_p;
  1858. {
  1859.   tree type0, type1;
  1860.   register enum tree_code code0, code1;
  1861.   tree op0, op1;
  1862.  
  1863.   /* Expression code to give to the expression when it is built.
  1864.      Normally this is CODE, which is what the caller asked for,
  1865.      but in some special cases we change it.  */
  1866.   register enum tree_code resultcode = code;
  1867.  
  1868.   /* Data type in which the computation is to be performed.
  1869.      In the simplest cases this is the common type of the arguments.  */
  1870.   register tree result_type = NULL;
  1871.  
  1872.   /* Nonzero means operands have already been type-converted
  1873.      in whatever way is necessary.
  1874.      Zero means they need to be converted to RESULT_TYPE.  */
  1875.   int converted = 0;
  1876.  
  1877.   /* Nonzero means after finally constructing the expression
  1878.      give it this type.  Otherwise, give it type RESULT_TYPE.  */
  1879.   tree final_type = 0;
  1880.  
  1881.   /* Nonzero if this is an operation like MIN or MAX which can
  1882.      safely be computed in short if both args are promoted shorts.
  1883.      Also implies COMMON.
  1884.      -1 indicates a bitwise operation; this makes a difference
  1885.      in the exact conditions for when it is safe to do the operation
  1886.      in a narrower mode.  */
  1887.   int shorten = 0;
  1888.  
  1889.   /* Nonzero if this is a comparison operation;
  1890.      if both args are promoted shorts, compare the original shorts.
  1891.      Also implies COMMON.  */
  1892.   int short_compare = 0;
  1893.  
  1894.   /* Nonzero if this is a right-shift operation, which can be computed on the
  1895.      original short and then promoted if the operand is a promoted short.  */
  1896.   int short_shift = 0;
  1897.  
  1898.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  1899.   int common = 0;
  1900.  
  1901.   if (convert_p)
  1902.     {
  1903.       op0 = default_conversion (orig_op0);
  1904.       op1 = default_conversion (orig_op1);
  1905.     }
  1906.   else
  1907.     {
  1908.       op0 = orig_op0;
  1909.       op1 = orig_op1;
  1910.     }
  1911.  
  1912.   type0 = TREE_TYPE (op0);
  1913.   type1 = TREE_TYPE (op1);
  1914.  
  1915.   /* The expression codes of the data types of the arguments tell us
  1916.      whether the arguments are integers, floating, pointers, etc.  */
  1917.   code0 = TREE_CODE (type0);
  1918.   code1 = TREE_CODE (type1);
  1919.  
  1920.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  1921.   STRIP_TYPE_NOPS (op0);
  1922.   STRIP_TYPE_NOPS (op1);
  1923.  
  1924.   /* If an error was already reported for one of the arguments,
  1925.      avoid reporting another error.  */
  1926.  
  1927.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  1928.     return error_mark_node;
  1929.  
  1930.   switch (code)
  1931.     {
  1932.     case PLUS_EXPR:
  1933.       /* Handle the pointer + int case.  */
  1934.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1935.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  1936.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  1937.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  1938.       else
  1939.     common = 1;
  1940.       break;
  1941.  
  1942.     case MINUS_EXPR:
  1943.       /* Subtraction of two similar pointers.
  1944.      We must subtract them as integers, then divide by object size.  */
  1945.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  1946.       && comp_target_types (type0, type1))
  1947.     return pointer_diff (op0, op1);
  1948.       /* Handle pointer minus int.  Just like pointer plus int.  */
  1949.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1950.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  1951.       else
  1952.     common = 1;
  1953.       break;
  1954.  
  1955.     case MULT_EXPR:
  1956.       common = 1;
  1957.       break;
  1958.  
  1959.     case TRUNC_DIV_EXPR:
  1960.     case CEIL_DIV_EXPR:
  1961.     case FLOOR_DIV_EXPR:
  1962.     case ROUND_DIV_EXPR:
  1963.     case EXACT_DIV_EXPR:
  1964.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
  1965.        || code0 == COMPLEX_TYPE)
  1966.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
  1967.           || code1 == COMPLEX_TYPE))
  1968.     {
  1969.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  1970.         resultcode = RDIV_EXPR;
  1971.       else
  1972.         /* When dividing two signed integers, you have to promote to int.
  1973.            E.g. (short) -32868 / (short) -1 doesn't fit in a short.  */
  1974.         shorten = TREE_UNSIGNED (orig_op0);
  1975.       common = 1;
  1976.     }
  1977.       break;
  1978.  
  1979.     case BIT_AND_EXPR:
  1980.     case BIT_ANDTC_EXPR:
  1981.     case BIT_IOR_EXPR:
  1982.     case BIT_XOR_EXPR:
  1983.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  1984.     shorten = -1;
  1985.       /* If one operand is a constant, and the other is a short type
  1986.      that has been converted to an int,
  1987.      really do the work in the short type and then convert the
  1988.      result to int.  If we are lucky, the constant will be 0 or 1
  1989.      in the short type, making the entire operation go away.  */
  1990.       if (TREE_CODE (op0) == INTEGER_CST
  1991.       && TREE_CODE (op1) == NOP_EXPR
  1992.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  1993.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  1994.     {
  1995.       final_type = result_type;
  1996.       op1 = TREE_OPERAND (op1, 0);
  1997.       result_type = TREE_TYPE (op1);
  1998.     }
  1999.       if (TREE_CODE (op1) == INTEGER_CST
  2000.       && TREE_CODE (op0) == NOP_EXPR
  2001.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  2002.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  2003.     {
  2004.       final_type = result_type;
  2005.       op0 = TREE_OPERAND (op0, 0);
  2006.       result_type = TREE_TYPE (op0);
  2007.     }
  2008.       break;
  2009.  
  2010.     case TRUNC_MOD_EXPR:
  2011.     case FLOOR_MOD_EXPR:
  2012.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2013.     {
  2014.       /* Although it would be tempting to shorten always here, that loses
  2015.          on some targets, since the modulo instruction is undefined if the
  2016.          quotient can't be represented in the computation mode.  We shorten
  2017.          only if unsigned or if dividing by something we know != -1.  */
  2018.       shorten = (TREE_UNSIGNED (orig_op0)
  2019.              || (TREE_CODE (op1) == INTEGER_CST
  2020.              && (TREE_INT_CST_LOW (op1) != -1
  2021.                  || TREE_INT_CST_HIGH (op1) != -1)));
  2022.       common = 1;
  2023.     }
  2024.       break;
  2025.  
  2026.     case TRUTH_ANDIF_EXPR:
  2027.     case TRUTH_ORIF_EXPR:
  2028.     case TRUTH_AND_EXPR:
  2029.     case TRUTH_OR_EXPR:
  2030.     case TRUTH_XOR_EXPR:
  2031.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
  2032.        || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
  2033.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
  2034.           || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
  2035.     {
  2036.       /* Result of these operations is always an int,
  2037.          but that does not mean the operands should be
  2038.          converted to ints!  */
  2039.       result_type = integer_type_node;
  2040.       op0 = truthvalue_conversion (op0);
  2041.       op1 = truthvalue_conversion (op1);
  2042.       converted = 1;
  2043.     }
  2044.       break;
  2045.  
  2046.       /* Shift operations: result has same type as first operand;
  2047.      always convert second operand to int.
  2048.      Also set SHORT_SHIFT if shifting rightward.  */
  2049.  
  2050.     case RSHIFT_EXPR:
  2051.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2052.     {
  2053.       if (TREE_CODE (op1) == INTEGER_CST)
  2054.         {
  2055.           if (tree_int_cst_lt (op1, integer_zero_node))
  2056.         warning ("right shift count is negative");
  2057.           else
  2058.         {
  2059.           if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
  2060.             short_shift = 1;
  2061.           if (TREE_INT_CST_HIGH (op1) != 0
  2062.               || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2063.               >= TYPE_PRECISION (type0)))
  2064.             warning ("right shift count >= width of type");
  2065.         }
  2066.         }
  2067.       /* Use the type of the value to be shifted.
  2068.          This is what most traditional C compilers do.  */
  2069.       result_type = type0;
  2070.       /* Unless traditional, convert the shift-count to an integer,
  2071.          regardless of size of value being shifted.  */
  2072.       if (! flag_traditional)
  2073.         {
  2074.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2075.         op1 = convert (integer_type_node, op1);
  2076.           /* Avoid converting op1 to result_type later.  */
  2077.           converted = 1;
  2078.         }
  2079.     }
  2080.       break;
  2081.  
  2082.     case LSHIFT_EXPR:
  2083.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2084.     {
  2085.       if (TREE_CODE (op1) == INTEGER_CST)
  2086.         {
  2087.           if (tree_int_cst_lt (op1, integer_zero_node))
  2088.         warning ("left shift count is negative");
  2089.           else if (TREE_INT_CST_HIGH (op1) != 0
  2090.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2091.                >= TYPE_PRECISION (type0)))
  2092.         warning ("left shift count >= width of type");
  2093.         }
  2094.       /* Use the type of the value to be shifted.
  2095.          This is what most traditional C compilers do.  */
  2096.       result_type = type0;
  2097.       /* Unless traditional, convert the shift-count to an integer,
  2098.          regardless of size of value being shifted.  */
  2099.       if (! flag_traditional)
  2100.         {
  2101.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2102.         op1 = convert (integer_type_node, op1);
  2103.           /* Avoid converting op1 to result_type later.  */
  2104.           converted = 1;
  2105.         }
  2106.     }
  2107.       break;
  2108.  
  2109.     case RROTATE_EXPR:
  2110.     case LROTATE_EXPR:
  2111.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2112.     {
  2113.       if (TREE_CODE (op1) == INTEGER_CST)
  2114.         {
  2115.           if (tree_int_cst_lt (op1, integer_zero_node))
  2116.         warning ("shift count is negative");
  2117.           else if (TREE_INT_CST_HIGH (op1) != 0
  2118.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2119.                >= TYPE_PRECISION (type0)))
  2120.         warning ("shift count >= width of type");
  2121.         }
  2122.       /* Use the type of the value to be shifted.
  2123.          This is what most traditional C compilers do.  */
  2124.       result_type = type0;
  2125.       /* Unless traditional, convert the shift-count to an integer,
  2126.          regardless of size of value being shifted.  */
  2127.       if (! flag_traditional)
  2128.         {
  2129.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2130.         op1 = convert (integer_type_node, op1);
  2131.           /* Avoid converting op1 to result_type later.  */
  2132.           converted = 1;
  2133.         }
  2134.     }
  2135.       break;
  2136.  
  2137.     case EQ_EXPR:
  2138.     case NE_EXPR:
  2139.       /* Result of comparison is always int,
  2140.      but don't convert the args to int!  */
  2141.       result_type = integer_type_node;
  2142.       converted = 1;
  2143.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
  2144.        || code0 == COMPLEX_TYPE)
  2145.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
  2146.           || code1 == COMPLEX_TYPE))
  2147.     short_compare = 1;
  2148.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2149.     {
  2150.       register tree tt0 = TREE_TYPE (type0);
  2151.       register tree tt1 = TREE_TYPE (type1);
  2152.       /* Anything compares with void *.  void * compares with anything.
  2153.          Otherwise, the targets must be compatible
  2154.          and both must be object or both incomplete.  */
  2155.       if (comp_target_types (type0, type1))
  2156.         ;
  2157.       else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
  2158.         {
  2159.           /* op0 != orig_op0 detects the case of something
  2160.          whose value is 0 but which isn't a valid null ptr const.  */
  2161.           if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
  2162.           && TREE_CODE (tt1) == FUNCTION_TYPE)
  2163.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2164.         }
  2165.       else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
  2166.         {
  2167.           if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
  2168.           && TREE_CODE (tt0) == FUNCTION_TYPE)
  2169.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2170.         }
  2171.       else
  2172.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2173.     }
  2174.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2175.            && integer_zerop (op1))
  2176.     op1 = null_pointer_node;
  2177.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2178.            && integer_zerop (op0))
  2179.     op0 = null_pointer_node;
  2180.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2181.     {
  2182.       if (! flag_traditional)
  2183.         pedwarn ("comparison between pointer and integer");
  2184.       op1 = convert (TREE_TYPE (op0), op1);
  2185.     }
  2186.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2187.     {
  2188.       if (! flag_traditional)
  2189.         pedwarn ("comparison between pointer and integer");
  2190.       op0 = convert (TREE_TYPE (op1), op0);
  2191.     }
  2192.       else
  2193.     /* If args are not valid, clear out RESULT_TYPE
  2194.        to cause an error message later.  */
  2195.     result_type = 0;
  2196.       break;
  2197.  
  2198.     case MAX_EXPR:
  2199.     case MIN_EXPR:
  2200.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2201.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2202.     shorten = 1;
  2203.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2204.     {
  2205.       if (! comp_target_types (type0, type1))
  2206.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2207.       else if (pedantic 
  2208.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2209.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2210.       result_type = common_type (type0, type1);
  2211.     }
  2212.       break;
  2213.  
  2214.     case LE_EXPR:
  2215.     case GE_EXPR:
  2216.     case LT_EXPR:
  2217.     case GT_EXPR:
  2218.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2219.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2220.     short_compare = 1;
  2221.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2222.     {
  2223.       if (! comp_target_types (type0, type1))
  2224.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2225.       else if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
  2226.            != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
  2227.         pedwarn ("comparison of complete and incomplete pointers");
  2228.       else if (pedantic 
  2229.            && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2230.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2231.       result_type = integer_type_node;
  2232.     }
  2233.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2234.            && integer_zerop (op1))
  2235.     {
  2236.       result_type = integer_type_node;
  2237.       op1 = null_pointer_node;
  2238.       if (pedantic)
  2239.         pedwarn ("ordered comparison of pointer with integer zero");
  2240.     }
  2241.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2242.            && integer_zerop (op0))
  2243.     {
  2244.       result_type = integer_type_node;
  2245.       op0 = null_pointer_node;
  2246.       if (pedantic)
  2247.         pedwarn ("ordered comparison of pointer with integer zero");
  2248.     }
  2249.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2250.     {
  2251.       result_type = integer_type_node;
  2252.       if (! flag_traditional)
  2253.         pedwarn ("comparison between pointer and integer");
  2254.       op1 = convert (TREE_TYPE (op0), op1);
  2255.     }
  2256.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2257.     {
  2258.       result_type = integer_type_node;
  2259.       if (! flag_traditional)
  2260.         pedwarn ("comparison between pointer and integer");
  2261.       op0 = convert (TREE_TYPE (op1), op0);
  2262.     }
  2263.       converted = 1;
  2264.       break;
  2265.     }
  2266.  
  2267.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
  2268.       &&
  2269.       (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
  2270.     {
  2271.       int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
  2272.  
  2273.       if (shorten || common || short_compare)
  2274.     result_type = common_type (type0, type1);
  2275.  
  2276.       /* For certain operations (which identify themselves by shorten != 0)
  2277.      if both args were extended from the same smaller type,
  2278.      do the arithmetic in that type and then extend.
  2279.  
  2280.      shorten !=0 and !=1 indicates a bitwise operation.
  2281.      For them, this optimization is safe only if
  2282.      both args are zero-extended or both are sign-extended.
  2283.      Otherwise, we might change the result.
  2284.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  2285.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  2286.  
  2287.       if (shorten && none_complex)
  2288.     {
  2289.       int unsigned0, unsigned1;
  2290.       tree arg0 = get_narrower (op0, &unsigned0);
  2291.       tree arg1 = get_narrower (op1, &unsigned1);
  2292.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  2293.       int uns = TREE_UNSIGNED (result_type);
  2294.       tree type;
  2295.  
  2296.       final_type = result_type;
  2297.  
  2298.       /* Handle the case that OP0 (or OP1) does not *contain* a conversion
  2299.          but it *requires* conversion to FINAL_TYPE.  */
  2300.  
  2301.       if ((TYPE_PRECISION (TREE_TYPE (op0))
  2302.            == TYPE_PRECISION (TREE_TYPE (arg0)))
  2303.           && TREE_TYPE (op0) != final_type)
  2304.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  2305.       if ((TYPE_PRECISION (TREE_TYPE (op1))
  2306.            == TYPE_PRECISION (TREE_TYPE (arg1)))
  2307.           && TREE_TYPE (op1) != final_type)
  2308.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  2309.  
  2310.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  2311.  
  2312.       /* For bitwise operations, signedness of nominal type
  2313.          does not matter.  Consider only how operands were extended.  */
  2314.       if (shorten == -1)
  2315.         uns = unsigned0;
  2316.  
  2317.       /* Note that in all three cases below we refrain from optimizing
  2318.          an unsigned operation on sign-extended args.
  2319.          That would not be valid.  */
  2320.  
  2321.       /* Both args variable: if both extended in same way
  2322.          from same width, do it in that width.
  2323.          Do it unsigned if args were zero-extended.  */
  2324.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  2325.            < TYPE_PRECISION (result_type))
  2326.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  2327.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  2328.           && unsigned0 == unsigned1
  2329.           && (unsigned0 || !uns))
  2330.         result_type
  2331.           = signed_or_unsigned_type (unsigned0,
  2332.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  2333.       else if (TREE_CODE (arg0) == INTEGER_CST
  2334.            && (unsigned1 || !uns)
  2335.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  2336.                < TYPE_PRECISION (result_type))
  2337.            && (type = signed_or_unsigned_type (unsigned1,
  2338.                                TREE_TYPE (arg1)),
  2339.                int_fits_type_p (arg0, type)))
  2340.         result_type = type;
  2341.       else if (TREE_CODE (arg1) == INTEGER_CST
  2342.            && (unsigned0 || !uns)
  2343.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  2344.                < TYPE_PRECISION (result_type))
  2345.            && (type = signed_or_unsigned_type (unsigned0,
  2346.                                TREE_TYPE (arg0)),
  2347.                int_fits_type_p (arg1, type)))
  2348.         result_type = type;
  2349.     }
  2350.  
  2351.       /* Shifts can be shortened if shifting right.  */
  2352.  
  2353.       if (short_shift)
  2354.     {
  2355.       int unsigned_arg;
  2356.       tree arg0 = get_narrower (op0, &unsigned_arg);
  2357.  
  2358.       final_type = result_type;
  2359.  
  2360.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  2361.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  2362.  
  2363.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  2364.           /* If arg is sign-extended and then unsigned-shifted,
  2365.          we can simulate this with a signed shift in arg's type
  2366.          only if the extended result is at least twice as wide
  2367.          as the arg.  Otherwise, the shift could use up all the
  2368.          ones made by sign-extension and bring in zeros.
  2369.          We can't optimize that case at all, but in most machines
  2370.          it never happens because available widths are 2**N.  */
  2371.           && (!TREE_UNSIGNED (final_type)
  2372.           || unsigned_arg
  2373.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  2374.         {
  2375.           /* Do an unsigned shift if the operand was zero-extended.  */
  2376.           result_type
  2377.         = signed_or_unsigned_type (unsigned_arg,
  2378.                        TREE_TYPE (arg0));
  2379.           /* Convert value-to-be-shifted to that type.  */
  2380.           if (TREE_TYPE (op0) != result_type)
  2381.         op0 = convert (result_type, op0);
  2382.           converted = 1;
  2383.         }
  2384.     }
  2385.  
  2386.       /* Comparison operations are shortened too but differently.
  2387.      They identify themselves by setting short_compare = 1.  */
  2388.  
  2389.       if (short_compare && none_complex)
  2390.     {
  2391.       /* Don't write &op0, etc., because that would prevent op0
  2392.          from being kept in a register.
  2393.          Instead, make copies of the our local variables and
  2394.          pass the copies by reference, then copy them back afterward.  */
  2395.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  2396.       enum tree_code xresultcode = resultcode;
  2397.       tree val 
  2398.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  2399.       if (val != 0)
  2400.         return val;
  2401.       op0 = xop0, op1 = xop1, result_type = xresult_type;
  2402.       resultcode = xresultcode;
  2403.  
  2404.       if (extra_warnings)
  2405.         {
  2406.           tree op0_type = TREE_TYPE (orig_op0);
  2407.           tree op1_type = TREE_TYPE (orig_op1);
  2408.           int op0_unsigned = TREE_UNSIGNED (op0_type);
  2409.           int op1_unsigned = TREE_UNSIGNED (op1_type);
  2410.  
  2411.           /* Give warnings for comparisons between signed and unsigned
  2412.          quantities that will fail.  Do not warn if the signed quantity
  2413.          is an unsuffixed integer literal (or some static constant
  2414.          expression involving such literals) and it is positive.
  2415.          Do not warn if the width of the unsigned quantity is less
  2416.          than that of the signed quantity, since in this case all
  2417.          values of the unsigned quantity fit in the signed quantity.
  2418.          Do not warn if the signed type is the same size as the
  2419.          result_type since sign extension does not cause trouble in
  2420.          this case.  */
  2421.           /* Do the checking based on the original operand trees, so that
  2422.          casts will be considered, but default promotions won't be.  */
  2423.           if (op0_unsigned != op1_unsigned
  2424.           && ((op0_unsigned
  2425.                && TYPE_PRECISION (op0_type) >= TYPE_PRECISION (op1_type)
  2426.                && TYPE_PRECISION (op0_type) < TYPE_PRECISION (result_type)
  2427.                && (TREE_CODE (op1) != INTEGER_CST
  2428.                || (TREE_CODE (op1) == INTEGER_CST
  2429.                    && INT_CST_LT (op1, integer_zero_node))))
  2430.               ||
  2431.               (op1_unsigned
  2432.                && TYPE_PRECISION (op1_type) >= TYPE_PRECISION (op0_type)
  2433.                && TYPE_PRECISION (op1_type) < TYPE_PRECISION (result_type)
  2434.                && (TREE_CODE (op0) != INTEGER_CST
  2435.                || (TREE_CODE (op0) == INTEGER_CST
  2436.                    && INT_CST_LT (op0, integer_zero_node))))))
  2437.         warning ("comparison between signed and unsigned");
  2438.         }
  2439.     }
  2440.     }
  2441.  
  2442.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  2443.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  2444.      Then the expression will be built.
  2445.      It will be given type FINAL_TYPE if that is nonzero;
  2446.      otherwise, it will be given type RESULT_TYPE.  */
  2447.  
  2448.   if (!result_type)
  2449.     {
  2450.       binary_op_error (code);
  2451.       return error_mark_node;
  2452.     }
  2453.  
  2454.   if (! converted)
  2455.     {
  2456.       if (TREE_TYPE (op0) != result_type)
  2457.     op0 = convert (result_type, op0); 
  2458.       if (TREE_TYPE (op1) != result_type)
  2459.     op1 = convert (result_type, op1); 
  2460.     }
  2461.  
  2462.   {
  2463.     register tree result = build (resultcode, result_type, op0, op1);
  2464.     register tree folded;
  2465.  
  2466.     folded = fold (result);
  2467.     if (folded == result)
  2468.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2469.     if (final_type != 0)
  2470.       return convert (final_type, folded);
  2471.     return folded;
  2472.   }
  2473. }
  2474.  
  2475. /* Return a tree for the sum or difference (RESULTCODE says which)
  2476.    of pointer PTROP and integer INTOP.  */
  2477.  
  2478. static tree
  2479. pointer_int_sum (resultcode, ptrop, intop)
  2480.      enum tree_code resultcode;
  2481.      register tree ptrop, intop;
  2482. {
  2483.   tree size_exp;
  2484.  
  2485.   register tree result;
  2486.   register tree folded;
  2487.  
  2488.   /* The result is a pointer of the same type that is being added.  */
  2489.  
  2490.   register tree result_type = TREE_TYPE (ptrop);
  2491.  
  2492.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  2493.     {
  2494.       if (pedantic || warn_pointer_arith)
  2495.     pedwarn ("pointer of type `void *' used in arithmetic");
  2496.       size_exp = integer_one_node;
  2497.     }
  2498.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  2499.     {
  2500.       if (pedantic || warn_pointer_arith)
  2501.     pedwarn ("pointer to a function used in arithmetic");
  2502.       size_exp = integer_one_node;
  2503.     }
  2504.   else
  2505.     size_exp = c_size_in_bytes (TREE_TYPE (result_type));
  2506.  
  2507.   /* If what we are about to multiply by the size of the elements
  2508.      contains a constant term, apply distributive law
  2509.      and multiply that constant term separately.
  2510.      This helps produce common subexpressions.  */
  2511.  
  2512.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  2513.       && ! TREE_CONSTANT (intop)
  2514.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  2515.       && TREE_CONSTANT (size_exp)
  2516.       /* If the constant comes from pointer subtraction,
  2517.      skip this optimization--it would cause an error.  */
  2518.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
  2519.     {
  2520.       enum tree_code subcode = resultcode;
  2521.       tree int_type = TREE_TYPE (intop);
  2522.       if (TREE_CODE (intop) == MINUS_EXPR)
  2523.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  2524.       /* Convert both subexpression types to the type of intop,
  2525.      because weird cases involving pointer arithmetic
  2526.      can result in a sum or difference with different type args.  */
  2527.       ptrop = build_binary_op (subcode, ptrop,
  2528.                    convert (int_type, TREE_OPERAND (intop, 1)), 1);
  2529.       intop = convert (int_type, TREE_OPERAND (intop, 0));
  2530.     }
  2531.  
  2532.   /* Convert the integer argument to a type the same size as a pointer
  2533.      so the multiply won't overflow spuriously.  */
  2534.  
  2535.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  2536.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  2537.  
  2538.   /* Replace the integer argument
  2539.      with a suitable product by the object size.  */
  2540.  
  2541.   intop = build_binary_op (MULT_EXPR, intop, size_exp, 1);
  2542.  
  2543.   /* Create the sum or difference.  */
  2544.  
  2545.   result = build (resultcode, result_type, ptrop, intop);
  2546.  
  2547.   folded = fold (result);
  2548.   if (folded == result)
  2549.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  2550.   return folded;
  2551. }
  2552.  
  2553. /* Return a tree for the difference of pointers OP0 and OP1.
  2554.    The resulting tree has type int.  */
  2555.  
  2556. static tree
  2557. pointer_diff (op0, op1)
  2558.      register tree op0, op1;
  2559. {
  2560.   register tree result, folded;
  2561.   tree restype = ptrdiff_type_node;
  2562.  
  2563.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  2564.  
  2565.   if (pedantic || warn_pointer_arith)
  2566.     {
  2567.       if (TREE_CODE (target_type) == VOID_TYPE)
  2568.     pedwarn ("pointer of type `void *' used in subtraction");
  2569.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  2570.     pedwarn ("pointer to a function used in subtraction");
  2571.     }
  2572.  
  2573.   /* First do the subtraction as integers;
  2574.      then drop through to build the divide operator.  */
  2575.  
  2576.   op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
  2577.              convert (restype, op1), 1);
  2578.   /* This generates an error if op1 is pointer to incomplete type.  */
  2579.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
  2580.     error ("arithmetic on pointer to an incomplete type");
  2581.   /* This generates an error if op0 is pointer to incomplete type.  */
  2582.   op1 = c_size_in_bytes (target_type);
  2583.  
  2584.   /* Divide by the size, in easiest possible way.  */
  2585.  
  2586.   result = build (EXACT_DIV_EXPR, restype, op0, op1);
  2587.  
  2588.   folded = fold (result);
  2589.   if (folded == result)
  2590.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2591.   return folded;
  2592. }
  2593.  
  2594. /* Construct and perhaps optimize a tree representation
  2595.    for a unary operation.  CODE, a tree_code, specifies the operation
  2596.    and XARG is the operand.  NOCONVERT nonzero suppresses
  2597.    the default promotions (such as from short to int).  */
  2598.  
  2599. tree
  2600. build_unary_op (code, xarg, noconvert)
  2601.      enum tree_code code;
  2602.      tree xarg;
  2603.      int noconvert;
  2604. {
  2605.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  2606.   register tree arg = xarg;
  2607.   register tree argtype = 0;
  2608.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  2609.   char *errstring = NULL;
  2610.   tree val;
  2611.  
  2612.   if (typecode == ERROR_MARK)
  2613.     return error_mark_node;
  2614.   if (typecode == ENUMERAL_TYPE)
  2615.     typecode = INTEGER_TYPE;
  2616.  
  2617.   switch (code)
  2618.     {
  2619.     case CONVERT_EXPR:
  2620.       /* This is used for unary plus, because a CONVERT_EXPR
  2621.      is enough to prevent anybody from looking inside for
  2622.      associativity, but won't generate any code.  */
  2623.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2624.         || typecode == COMPLEX_TYPE))
  2625.         errstring = "wrong type argument to unary plus";
  2626.       else if (!noconvert)
  2627.     arg = default_conversion (arg);
  2628.       break;
  2629.  
  2630.     case NEGATE_EXPR:
  2631.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2632.         || typecode == COMPLEX_TYPE))
  2633.         errstring = "wrong type argument to unary minus";
  2634.       else if (!noconvert)
  2635.     arg = default_conversion (arg);
  2636.       break;
  2637.  
  2638.     case BIT_NOT_EXPR:
  2639.       if (typecode == COMPLEX_TYPE)
  2640.     {
  2641.       code = CONJ_EXPR;
  2642.       if (!noconvert)
  2643.         arg = default_conversion (arg);
  2644.     }
  2645.       else if (typecode != INTEGER_TYPE)
  2646.         errstring = "wrong type argument to bit-complement";
  2647.       else if (!noconvert)
  2648.     arg = default_conversion (arg);
  2649.       break;
  2650.  
  2651.     case ABS_EXPR:
  2652.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2653.         || typecode == COMPLEX_TYPE))
  2654.         errstring = "wrong type argument to abs";
  2655.       else if (!noconvert)
  2656.     arg = default_conversion (arg);
  2657.       break;
  2658.  
  2659.     case CONJ_EXPR:
  2660.       /* Conjugating a real value is a no-op, but allow it anyway.  */
  2661.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2662.         || typecode == COMPLEX_TYPE))
  2663.     errstring = "wrong type argument to conjugation";
  2664.       else if (!noconvert)
  2665.     arg = default_conversion (arg);
  2666.       break;
  2667.  
  2668.     case TRUTH_NOT_EXPR:
  2669.       if (typecode != INTEGER_TYPE
  2670.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  2671.       && typecode != COMPLEX_TYPE
  2672.       /* These will convert to a pointer.  */
  2673.       && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
  2674.     {
  2675.       errstring = "wrong type argument to unary exclamation mark";
  2676.       break;
  2677.     }
  2678.       arg = truthvalue_conversion (arg);
  2679.       return invert_truthvalue (arg);
  2680.  
  2681.     case NOP_EXPR:
  2682.       break;
  2683.  
  2684.     case REALPART_EXPR:
  2685.       if (TREE_CODE (arg) == COMPLEX_CST)
  2686.     return TREE_REALPART (arg);
  2687.       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
  2688.     return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
  2689.       else
  2690.     return arg;
  2691.  
  2692.     case IMAGPART_EXPR:
  2693.       if (TREE_CODE (arg) == COMPLEX_CST)
  2694.     return TREE_IMAGPART (arg);
  2695.       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
  2696.     return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
  2697.       else
  2698.     return convert (TREE_TYPE (arg), integer_zero_node);
  2699.       
  2700.     case PREINCREMENT_EXPR:
  2701.     case POSTINCREMENT_EXPR:
  2702.     case PREDECREMENT_EXPR:
  2703.     case POSTDECREMENT_EXPR:
  2704.       /* Handle complex lvalues (when permitted)
  2705.      by reduction to simpler cases.  */
  2706.  
  2707.       val = unary_complex_lvalue (code, arg);
  2708.       if (val != 0)
  2709.     return val;
  2710.  
  2711.       /* Increment or decrement the real part of the value,
  2712.      and don't change the imaginary part.  */
  2713.       if (typecode == COMPLEX_TYPE)
  2714.     {
  2715.       tree real, imag;
  2716.  
  2717.       arg = stabilize_reference (arg);
  2718.       real = build_unary_op (REALPART_EXPR, arg, 1);
  2719.       imag = build_unary_op (IMAGPART_EXPR, arg, 1);
  2720.       return build (COMPLEX_EXPR, TREE_TYPE (arg),
  2721.             build_unary_op (code, real, 1), imag);
  2722.     }
  2723.  
  2724.       /* Report invalid types.  */
  2725.  
  2726.       if (typecode != POINTER_TYPE
  2727.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2728.     {
  2729.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2730.         errstring ="wrong type argument to increment";
  2731.       else
  2732.         errstring ="wrong type argument to decrement";
  2733.       break;
  2734.     }
  2735.  
  2736.       {
  2737.     register tree inc;
  2738.     tree result_type = TREE_TYPE (arg);
  2739.  
  2740.     arg = get_unwidened (arg, 0);
  2741.     argtype = TREE_TYPE (arg);
  2742.  
  2743.     /* Compute the increment.  */
  2744.  
  2745.     if (typecode == POINTER_TYPE)
  2746.       {
  2747.         /* If pointer target is an undefined struct,
  2748.            we just cannot know how to do the arithmetic.  */
  2749.         if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
  2750.           error ("%s of pointer to unknown structure",
  2751.                ((code == PREINCREMENT_EXPR
  2752.              || code == POSTINCREMENT_EXPR)
  2753.             ? "increment" : "decrement"));
  2754.         else if ((pedantic || warn_pointer_arith)
  2755.              && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
  2756.              || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
  2757.           pedwarn ("wrong type argument to %s",
  2758.                ((code == PREINCREMENT_EXPR
  2759.              || code == POSTINCREMENT_EXPR)
  2760.             ? "increment" : "decrement"));
  2761.         inc = c_sizeof_nowarn (TREE_TYPE (result_type));
  2762.       }
  2763.     else
  2764.       inc = integer_one_node;
  2765.  
  2766.     inc = convert (argtype, inc);
  2767.  
  2768.     /* Handle incrementing a cast-expression.  */
  2769.  
  2770.     while (1)
  2771.       switch (TREE_CODE (arg))
  2772.         {
  2773.         case NOP_EXPR:
  2774.         case CONVERT_EXPR:
  2775.         case FLOAT_EXPR:
  2776.         case FIX_TRUNC_EXPR:
  2777.         case FIX_FLOOR_EXPR:
  2778.         case FIX_ROUND_EXPR:
  2779.         case FIX_CEIL_EXPR:
  2780.           pedantic_lvalue_warning (CONVERT_EXPR);
  2781.           /* If the real type has the same machine representation
  2782.          as the type it is cast to, we can make better output
  2783.          by adding directly to the inside of the cast.  */
  2784.           if ((TREE_CODE (TREE_TYPE (arg))
  2785.            == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
  2786.           && (TYPE_MODE (TREE_TYPE (arg))
  2787.               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
  2788.         arg = TREE_OPERAND (arg, 0);
  2789.           else
  2790.         {
  2791.           tree incremented, modify, value;
  2792.           arg = stabilize_reference (arg);
  2793.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2794.             value = arg;
  2795.           else
  2796.             value = save_expr (arg);
  2797.           incremented = build (((code == PREINCREMENT_EXPR
  2798.                      || code == POSTINCREMENT_EXPR)
  2799.                     ? PLUS_EXPR : MINUS_EXPR),
  2800.                        argtype, value, inc);
  2801.           TREE_SIDE_EFFECTS (incremented) = 1;
  2802.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2803.           value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2804.           TREE_USED (value) = 1;
  2805.           return value;
  2806.         }
  2807.           break;
  2808.  
  2809.         default:
  2810.           goto give_up;
  2811.         }
  2812.       give_up:
  2813.  
  2814.     /* Complain about anything else that is not a true lvalue.  */
  2815.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2816.                     || code == POSTINCREMENT_EXPR)
  2817.                    ? "increment" : "decrement")))
  2818.       return error_mark_node;
  2819.  
  2820.     /* Report a read-only lvalue.  */
  2821.     if (TREE_READONLY (arg))
  2822.       readonly_warning (arg, 
  2823.                 ((code == PREINCREMENT_EXPR
  2824.                   || code == POSTINCREMENT_EXPR)
  2825.                  ? "increment" : "decrement"));
  2826.  
  2827.     val = build (code, TREE_TYPE (arg), arg, inc);
  2828.     TREE_SIDE_EFFECTS (val) = 1;
  2829.     val = convert (result_type, val);
  2830.     if (TREE_CODE (val) != code)
  2831.       TREE_NO_UNUSED_WARNING (val) = 1;
  2832.     return val;
  2833.       }
  2834.  
  2835.     case ADDR_EXPR:
  2836.       /* Note that this operation never does default_conversion
  2837.      regardless of NOCONVERT.  */
  2838.  
  2839.       /* Let &* cancel out to simplify resulting code.  */
  2840.       if (TREE_CODE (arg) == INDIRECT_REF)
  2841.     {
  2842.       /* Don't let this be an lvalue.  */
  2843.       if (lvalue_p (TREE_OPERAND (arg, 0)))
  2844.         return non_lvalue (TREE_OPERAND (arg, 0));
  2845.       return TREE_OPERAND (arg, 0);
  2846.     }
  2847.  
  2848.       /* For &x[y], return x+y */
  2849.       if (TREE_CODE (arg) == ARRAY_REF)
  2850.     {
  2851.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  2852.         return error_mark_node;
  2853.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2854.                   TREE_OPERAND (arg, 1), 1);
  2855.     }
  2856.  
  2857.       /* Handle complex lvalues (when permitted)
  2858.      by reduction to simpler cases.  */
  2859.       val = unary_complex_lvalue (code, arg);
  2860.       if (val != 0)
  2861.     return val;
  2862.  
  2863. #if 0 /* Turned off because inconsistent;
  2864.      float f; *&(int)f = 3.4 stores in int format
  2865.      whereas (int)f = 3.4 stores in float format.  */
  2866.       /* Address of a cast is just a cast of the address
  2867.      of the operand of the cast.  */
  2868.       switch (TREE_CODE (arg))
  2869.     {
  2870.     case NOP_EXPR:
  2871.     case CONVERT_EXPR:
  2872.     case FLOAT_EXPR:
  2873.     case FIX_TRUNC_EXPR:
  2874.     case FIX_FLOOR_EXPR:
  2875.     case FIX_ROUND_EXPR:
  2876.     case FIX_CEIL_EXPR:
  2877.       if (pedantic)
  2878.         pedwarn ("ANSI C forbids the address of a cast expression");
  2879.       return convert (build_pointer_type (TREE_TYPE (arg)),
  2880.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  2881.                       0));
  2882.     }
  2883. #endif
  2884.  
  2885.       /* Allow the address of a constructor if all the elements
  2886.      are constant.  */
  2887.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  2888.     ;
  2889.       /* Anything not already handled and not a true memory reference
  2890.      is an error.  */
  2891.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  2892.     return error_mark_node;
  2893.  
  2894.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  2895.       argtype = TREE_TYPE (arg);
  2896.       /* If the lvalue is const or volatile,
  2897.      merge that into the type that the address will point to.  */
  2898.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  2899.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  2900.     {
  2901.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  2902.         argtype = c_build_type_variant (argtype,
  2903.                         TREE_READONLY (arg),
  2904.                         TREE_THIS_VOLATILE (arg));
  2905.     }
  2906.  
  2907.       argtype = build_pointer_type (argtype);
  2908.  
  2909.       if (mark_addressable (arg) == 0)
  2910.     return error_mark_node;
  2911.  
  2912.       {
  2913.     tree addr;
  2914.  
  2915.     if (TREE_CODE (arg) == COMPONENT_REF)
  2916.       {
  2917.         tree field = TREE_OPERAND (arg, 1);
  2918.  
  2919.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  2920.  
  2921.         if (DECL_BIT_FIELD (field))
  2922.           {
  2923.         error ("attempt to take address of bit-field structure member `%s'",
  2924.                IDENTIFIER_POINTER (DECL_NAME (field)));
  2925.         return error_mark_node;
  2926.           }
  2927.  
  2928.         addr = convert (argtype, addr);
  2929.  
  2930.         if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  2931.           {
  2932.         tree offset
  2933.           = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  2934.                 size_int (BITS_PER_UNIT));
  2935.         int flag = TREE_CONSTANT (addr);
  2936.         addr = fold (build (PLUS_EXPR, argtype,
  2937.                     addr, convert (argtype, offset)));
  2938.         TREE_CONSTANT (addr) = flag;
  2939.           }
  2940.       }
  2941.     else
  2942.       addr = build1 (code, argtype, arg);
  2943.  
  2944.     /* Address of a static or external variable or
  2945.        file-scope function counts as a constant.  */
  2946.     if (staticp (arg)
  2947.         && ! (TREE_CODE (arg) == FUNCTION_DECL
  2948.           && DECL_CONTEXT (arg) != 0))
  2949.       TREE_CONSTANT (addr) = 1;
  2950.     return addr;
  2951.       }
  2952.     }
  2953.  
  2954.   if (!errstring)
  2955.     {
  2956.       if (argtype == 0)
  2957.     argtype = TREE_TYPE (arg);
  2958.       return fold (build1 (code, argtype, arg));
  2959.     }
  2960.  
  2961.   error (errstring);
  2962.   return error_mark_node;
  2963. }
  2964.  
  2965. #if 0
  2966. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  2967.    convert ARG with the same conversions in the same order
  2968.    and return the result.  */
  2969.  
  2970. static tree
  2971. convert_sequence (conversions, arg)
  2972.      tree conversions;
  2973.      tree arg;
  2974. {
  2975.   switch (TREE_CODE (conversions))
  2976.     {
  2977.     case NOP_EXPR:
  2978.     case CONVERT_EXPR:
  2979.     case FLOAT_EXPR:
  2980.     case FIX_TRUNC_EXPR:
  2981.     case FIX_FLOOR_EXPR:
  2982.     case FIX_ROUND_EXPR:
  2983.     case FIX_CEIL_EXPR:
  2984.       return convert (TREE_TYPE (conversions),
  2985.               convert_sequence (TREE_OPERAND (conversions, 0),
  2986.                     arg));
  2987.  
  2988.     default:
  2989.       return arg;
  2990.     }
  2991. }
  2992. #endif /* 0 */
  2993.  
  2994. /* Return nonzero if REF is an lvalue valid for this language.
  2995.    Lvalues can be assigned, unless their type has TYPE_READONLY.
  2996.    Lvalues can have their address taken, unless they have DECL_REGISTER.  */
  2997.  
  2998. int
  2999. lvalue_p (ref)
  3000.      tree ref;
  3001. {
  3002.   register enum tree_code code = TREE_CODE (ref);
  3003.  
  3004.   switch (code)
  3005.     {
  3006.     case REALPART_EXPR:
  3007.     case IMAGPART_EXPR:
  3008.     case COMPONENT_REF:
  3009.       return lvalue_p (TREE_OPERAND (ref, 0));
  3010.  
  3011.     case STRING_CST:
  3012.       return 1;
  3013.  
  3014.     case INDIRECT_REF:
  3015.     case ARRAY_REF:
  3016.     case VAR_DECL:
  3017.     case PARM_DECL:
  3018.     case RESULT_DECL:
  3019.     case ERROR_MARK:
  3020.       if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  3021.       && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  3022.     return 1;
  3023.       break;
  3024.     }
  3025.   return 0;
  3026. }
  3027.  
  3028. /* Return nonzero if REF is an lvalue valid for this language;
  3029.    otherwise, print an error message and return zero.  */
  3030.  
  3031. int
  3032. lvalue_or_else (ref, string)
  3033.      tree ref;
  3034.      char *string;
  3035. {
  3036.   int win = lvalue_p (ref);
  3037.   if (! win)
  3038.     error ("invalid lvalue in %s", string);
  3039.   return win;
  3040. }
  3041.  
  3042. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  3043.    for certain kinds of expressions which are not really lvalues
  3044.    but which we can accept as lvalues.
  3045.  
  3046.    If ARG is not a kind of expression we can handle, return zero.  */
  3047.    
  3048. static tree
  3049. unary_complex_lvalue (code, arg)
  3050.      enum tree_code code;
  3051.      tree arg;
  3052. {
  3053.   /* Handle (a, b) used as an "lvalue".  */
  3054.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  3055.     {
  3056.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  3057.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3058.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  3059.             TREE_OPERAND (arg, 0), real_result);
  3060.     }
  3061.  
  3062.   /* Handle (a ? b : c) used as an "lvalue".  */
  3063.   if (TREE_CODE (arg) == COND_EXPR)
  3064.     {
  3065.       pedantic_lvalue_warning (COND_EXPR);
  3066.       return (build_conditional_expr
  3067.           (TREE_OPERAND (arg, 0),
  3068.            build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  3069.            build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  3070.     }
  3071.  
  3072.   return 0;
  3073. }
  3074.  
  3075. /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
  3076.    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
  3077.  
  3078. static void
  3079. pedantic_lvalue_warning (code)
  3080.      enum tree_code code;
  3081. {
  3082.   if (pedantic)
  3083.     pedwarn ("ANSI C forbids use of %s expressions as lvalues",
  3084.          code == COND_EXPR ? "conditional"
  3085.          : code == COMPOUND_EXPR ? "compound" : "cast");
  3086. }
  3087.  
  3088. /* Warn about storing in something that is `const'.  */
  3089.  
  3090. void
  3091. readonly_warning (arg, string)
  3092.      tree arg;
  3093.      char *string;
  3094. {
  3095.   char buf[80];
  3096.   strcpy (buf, string);
  3097.  
  3098.   /* Forbid assignments to iterators.  */
  3099.   if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
  3100.     {
  3101.       strcat (buf, " of iterator `%s'");
  3102.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  3103.     }
  3104.  
  3105.   if (TREE_CODE (arg) == COMPONENT_REF)
  3106.     {
  3107.       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
  3108.     readonly_warning (TREE_OPERAND (arg, 0), string);
  3109.       else
  3110.     {
  3111.       strcat (buf, " of read-only member `%s'");
  3112.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  3113.     }
  3114.     }
  3115.   else if (TREE_CODE (arg) == VAR_DECL)
  3116.     {
  3117.       strcat (buf, " of read-only variable `%s'");
  3118.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  3119.     }
  3120.   else
  3121.     {
  3122.       pedwarn ("%s of read-only location", buf);
  3123.     }
  3124. }
  3125.  
  3126. /* Mark EXP saying that we need to be able to take the
  3127.    address of it; it should not be allocated in a register.
  3128.    Value is 1 if successful.  */
  3129.  
  3130. int
  3131. mark_addressable (exp)
  3132.      tree exp;
  3133. {
  3134.   register tree x = exp;
  3135.   while (1)
  3136.     switch (TREE_CODE (x))
  3137.       {
  3138.       case ADDR_EXPR:
  3139.       case COMPONENT_REF:
  3140.       case ARRAY_REF:
  3141.       case REALPART_EXPR:
  3142.       case IMAGPART_EXPR:
  3143.     x = TREE_OPERAND (x, 0);
  3144.     break;
  3145.  
  3146.       case CONSTRUCTOR:
  3147.     TREE_ADDRESSABLE (x) = 1;
  3148.     return 1;
  3149.  
  3150.       case VAR_DECL:
  3151.       case CONST_DECL:
  3152.       case PARM_DECL:
  3153.       case RESULT_DECL:
  3154.     if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
  3155.         && DECL_NONLOCAL (x))
  3156.       {
  3157.         if (TREE_PUBLIC (x))
  3158.           {
  3159.         error ("global register variable `%s' used in nested function",
  3160.                IDENTIFIER_POINTER (DECL_NAME (x)));
  3161.         return 0;
  3162.           }
  3163.         pedwarn ("register variable `%s' used in nested function",
  3164.              IDENTIFIER_POINTER (DECL_NAME (x)));
  3165.       }
  3166.     else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
  3167.       {
  3168.         if (TREE_PUBLIC (x))
  3169.           {
  3170.         error ("address of global register variable `%s' requested",
  3171.                IDENTIFIER_POINTER (DECL_NAME (x)));
  3172.         return 0;
  3173.           }
  3174.         pedwarn ("address of register variable `%s' requested",
  3175.              IDENTIFIER_POINTER (DECL_NAME (x)));
  3176.       }
  3177.     put_var_into_stack (x);
  3178.  
  3179.     /* drops in */
  3180.       case FUNCTION_DECL:
  3181.     TREE_ADDRESSABLE (x) = 1;
  3182. #if 0  /* poplevel deals with this now.  */
  3183.     if (DECL_CONTEXT (x) == 0)
  3184.       TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
  3185. #endif
  3186.  
  3187.       default:
  3188.     return 1;
  3189.     }
  3190. }
  3191.  
  3192. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  3193.  
  3194. tree
  3195. build_conditional_expr (ifexp, op1, op2)
  3196.      tree ifexp, op1, op2;
  3197. {
  3198.   register tree type1;
  3199.   register tree type2;
  3200.   register enum tree_code code1;
  3201.   register enum tree_code code2;
  3202.   register tree result_type = NULL;
  3203.   tree orig_op1 = op1, orig_op2 = op2;
  3204.  
  3205.   /* If second operand is omitted, it is the same as the first one;
  3206.      make sure it is calculated only once.  */
  3207.   if (op1 == 0)
  3208.     {
  3209.       if (pedantic)
  3210.     pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
  3211.       ifexp = op1 = save_expr (ifexp);
  3212.     }
  3213.  
  3214.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  3215.  
  3216. #if 0 /* Produces wrong result if within sizeof.  */
  3217.   /* Don't promote the operands separately if they promote
  3218.      the same way.  Return the unpromoted type and let the combined
  3219.      value get promoted if necessary.  */
  3220.  
  3221.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  3222.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  3223.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  3224.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  3225.     {
  3226.       if (TREE_CODE (ifexp) == INTEGER_CST)
  3227.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3228.  
  3229.       return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
  3230.     }
  3231. #endif
  3232.  
  3233.   /* Promote both alternatives.  */
  3234.  
  3235.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  3236.     op1 = default_conversion (op1);
  3237.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  3238.     op2 = default_conversion (op2);
  3239.  
  3240.   if (TREE_CODE (ifexp) == ERROR_MARK
  3241.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  3242.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  3243.     return error_mark_node;
  3244.  
  3245.   type1 = TREE_TYPE (op1);
  3246.   code1 = TREE_CODE (type1);
  3247.   type2 = TREE_TYPE (op2);
  3248.   code2 = TREE_CODE (type2);
  3249.       
  3250.   /* Quickly detect the usual case where op1 and op2 have the same type
  3251.      after promotion.  */
  3252.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
  3253.     {
  3254.       if (type1 == type2)
  3255.     result_type = type1;
  3256.       else
  3257.     result_type = TYPE_MAIN_VARIANT (type1);
  3258.     }
  3259.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  3260.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  3261.     {
  3262.       result_type = common_type (type1, type2);
  3263.     }
  3264.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  3265.     {
  3266.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  3267.     pedwarn ("ANSI C forbids conditional expr with only one void side");
  3268.       result_type = void_type_node;
  3269.     }
  3270.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  3271.     {
  3272.       if (comp_target_types (type1, type2))
  3273.     result_type = common_type (type1, type2);
  3274.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
  3275.            && TREE_CODE (orig_op1) != NOP_EXPR)
  3276.     result_type = qualify_type (type2, type1);
  3277.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
  3278.            && TREE_CODE (orig_op2) != NOP_EXPR)
  3279.     result_type = qualify_type (type1, type2);
  3280.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  3281.     {
  3282.       if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
  3283.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3284.       result_type = qualify_type (type1, type2);
  3285.     }
  3286.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  3287.     {
  3288.       if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
  3289.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3290.       result_type = qualify_type (type2, type1);
  3291.     }
  3292.       else
  3293.     {
  3294.       pedwarn ("pointer type mismatch in conditional expression");
  3295.       result_type = build_pointer_type (void_type_node);
  3296.     }
  3297.     }
  3298.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  3299.     {
  3300.       if (! integer_zerop (op2))
  3301.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3302.       else
  3303.     {
  3304.       op2 = null_pointer_node;
  3305. #if 0  /* The spec seems to say this is permitted.  */
  3306.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  3307.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3308. #endif
  3309.     }
  3310.       result_type = type1;
  3311.     }
  3312.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3313.     {
  3314.       if (!integer_zerop (op1))
  3315.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3316.       else
  3317.     {
  3318.       op1 = null_pointer_node;
  3319. #if 0  /* The spec seems to say this is permitted.  */
  3320.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  3321.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3322. #endif
  3323.     }
  3324.       result_type = type2;
  3325.     }
  3326.  
  3327.   if (!result_type)
  3328.     {
  3329.       if (flag_cond_mismatch)
  3330.     result_type = void_type_node;
  3331.       else
  3332.     {
  3333.       error ("type mismatch in conditional expression");
  3334.       return error_mark_node;
  3335.     }
  3336.     }
  3337.  
  3338.   /* Merge const and volatile flags of the incoming types.  */
  3339.   result_type
  3340.     = build_type_variant (result_type,
  3341.               TREE_READONLY (op1) || TREE_READONLY (op2),
  3342.               TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  3343.  
  3344.   if (result_type != TREE_TYPE (op1))
  3345.     op1 = convert_and_check (result_type, op1);
  3346.   if (result_type != TREE_TYPE (op2))
  3347.     op2 = convert_and_check (result_type, op2);
  3348.     
  3349. #if 0
  3350.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  3351.     {
  3352.       result_type = TREE_TYPE (op1);
  3353.       if (TREE_CONSTANT (ifexp))
  3354.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3355.  
  3356.       if (TYPE_MODE (result_type) == BLKmode)
  3357.     {
  3358.       register tree tempvar
  3359.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  3360.       register tree xop1 = build_modify_expr (tempvar, op1);
  3361.       register tree xop2 = build_modify_expr (tempvar, op2);
  3362.       register tree result = fold (build (COND_EXPR, result_type,
  3363.                           ifexp, xop1, xop2));
  3364.  
  3365.       layout_decl (tempvar, TYPE_ALIGN (result_type));
  3366.       /* No way to handle variable-sized objects here.
  3367.          I fear that the entire handling of BLKmode conditional exprs
  3368.          needs to be redone.  */
  3369.       if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
  3370.         abort ();
  3371.       DECL_RTL (tempvar)
  3372.         = assign_stack_local (DECL_MODE (tempvar),
  3373.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  3374.                    + BITS_PER_UNIT - 1)
  3375.                   / BITS_PER_UNIT,
  3376.                   0);
  3377.  
  3378.       TREE_SIDE_EFFECTS (result)
  3379.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  3380.           | TREE_SIDE_EFFECTS (op2);
  3381.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  3382.     }
  3383.     }
  3384. #endif /* 0 */
  3385.     
  3386.   if (TREE_CODE (ifexp) == INTEGER_CST)
  3387.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3388.  
  3389.   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
  3390. }
  3391.  
  3392. /* Given a list of expressions, return a compound expression
  3393.    that performs them all and returns the value of the last of them.  */
  3394.  
  3395. tree
  3396. build_compound_expr (list)
  3397.      tree list;
  3398. {
  3399.   return internal_build_compound_expr (list, TRUE);
  3400. }
  3401.  
  3402. static tree
  3403. internal_build_compound_expr (list, first_p)
  3404.      tree list;
  3405.      int first_p;
  3406. {
  3407.   register tree rest;
  3408.  
  3409.   if (TREE_CHAIN (list) == 0)
  3410.     {
  3411. #if 0 /* If something inside inhibited lvalueness, we should not override.  */
  3412.       /* Consider (x, y+0), which is not an lvalue since y+0 is not.  */
  3413.  
  3414.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3415.       if (TREE_CODE (list) == NON_LVALUE_EXPR)
  3416.     list = TREE_OPERAND (list, 0);
  3417. #endif
  3418.  
  3419.       /* Don't let (0, 0) be null pointer constant.  */
  3420.       if (!first_p && integer_zerop (TREE_VALUE (list)))
  3421.     return non_lvalue (TREE_VALUE (list));
  3422.       return TREE_VALUE (list);
  3423.     }
  3424.  
  3425.   if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
  3426.     {
  3427.       /* Convert arrays to pointers when there really is a comma operator.  */
  3428.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
  3429.     TREE_VALUE (TREE_CHAIN (list))
  3430.       = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
  3431.     }
  3432.  
  3433.   rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
  3434.  
  3435.   /* When pedantic, a compound expression can be neither an lvalue
  3436.      nor an integer constant expression.  */
  3437.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
  3438.     return rest;
  3439.  
  3440.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  3441. }
  3442.  
  3443. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  3444.  
  3445. tree
  3446. build_c_cast (type, expr)
  3447.      register tree type;
  3448.      tree expr;
  3449. {
  3450.   register tree value = expr;
  3451.   
  3452.   if (type == error_mark_node || expr == error_mark_node)
  3453.     return error_mark_node;
  3454.   type = TYPE_MAIN_VARIANT (type);
  3455.  
  3456. #if 0
  3457.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3458.   if (TREE_CODE (value) == NON_LVALUE_EXPR)
  3459.     value = TREE_OPERAND (value, 0);
  3460. #endif
  3461.  
  3462.   if (TREE_CODE (type) == ARRAY_TYPE)
  3463.     {
  3464.       error ("cast specifies array type");
  3465.       return error_mark_node;
  3466.     }
  3467.  
  3468.   if (TREE_CODE (type) == FUNCTION_TYPE)
  3469.     {
  3470.       error ("cast specifies function type");
  3471.       return error_mark_node;
  3472.     }
  3473.  
  3474.   if (type == TREE_TYPE (value))
  3475.     {
  3476.       if (pedantic)
  3477.     {
  3478.       if (TREE_CODE (type) == RECORD_TYPE
  3479.           || TREE_CODE (type) == UNION_TYPE)
  3480.         pedwarn ("ANSI C forbids casting nonscalar to the same type");
  3481.     }
  3482.     }
  3483.   else if (TREE_CODE (type) == UNION_TYPE)
  3484.     {
  3485.       tree field;
  3486.       if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  3487.       || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
  3488.     value = default_conversion (value);
  3489.  
  3490.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  3491.     if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
  3492.                TYPE_MAIN_VARIANT (TREE_TYPE (value))))
  3493.       break;
  3494.  
  3495.       if (field)
  3496.     {
  3497.       char *name;
  3498.       tree t;
  3499.  
  3500.       if (pedantic)
  3501.         pedwarn ("ANSI C forbids casts to union type");
  3502.       if (TYPE_NAME (type) != 0)
  3503.         {
  3504.           if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  3505.         name = IDENTIFIER_POINTER (TYPE_NAME (type));
  3506.           else
  3507.         name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  3508.         }
  3509.       else
  3510.         name = "";
  3511.       t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
  3512.                     build_tree_list (field, value)),
  3513.                0, 0);
  3514.       TREE_CONSTANT (t) = TREE_CONSTANT (value);
  3515.       return t;
  3516.     }
  3517.       error ("cast to union type from type not present in union");
  3518.       return error_mark_node;
  3519.     }
  3520.   else
  3521.     {
  3522.       tree otype, ovalue;
  3523.  
  3524.       /* If casting to void, avoid the error that would come
  3525.      from default_conversion in the case of a non-lvalue array.  */
  3526.       if (type == void_type_node)
  3527.     return build1 (CONVERT_EXPR, type, value);
  3528.  
  3529.       /* Convert functions and arrays to pointers,
  3530.      but don't convert any other types.  */
  3531.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  3532.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
  3533.     value = default_conversion (value);
  3534.       otype = TREE_TYPE (value);
  3535.  
  3536.       /* Optionally warn about potentially worrisome casts.  */
  3537.  
  3538.       if (warn_cast_qual
  3539.       && TREE_CODE (type) == POINTER_TYPE
  3540.       && TREE_CODE (otype) == POINTER_TYPE)
  3541.     {
  3542.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  3543.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  3544.         pedwarn ("cast discards `volatile' from pointer target type");
  3545.       if (TYPE_READONLY (TREE_TYPE (otype))
  3546.           && ! TYPE_READONLY (TREE_TYPE (type)))
  3547.         pedwarn ("cast discards `const' from pointer target type");
  3548.     }
  3549.  
  3550.       /* Warn about possible alignment problems.  */
  3551.       if (STRICT_ALIGNMENT && warn_cast_align
  3552.       && TREE_CODE (type) == POINTER_TYPE
  3553.       && TREE_CODE (otype) == POINTER_TYPE
  3554.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  3555.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  3556.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  3557.     warning ("cast increases required alignment of target type");
  3558.  
  3559.       if (TREE_CODE (type) == INTEGER_TYPE
  3560.       && TREE_CODE (otype) == POINTER_TYPE
  3561.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  3562.       && !TREE_CONSTANT (value))
  3563.     warning ("cast from pointer to integer of different size");
  3564.  
  3565.       if (TREE_CODE (type) == POINTER_TYPE
  3566.       && TREE_CODE (otype) == INTEGER_TYPE
  3567.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  3568. #if 0
  3569.       /* Don't warn about converting 0 to pointer,
  3570.          provided the 0 was explicit--not cast or made by folding.  */
  3571.       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
  3572. #endif
  3573.       /* Don't warn about converting any constant.  */
  3574.       && !TREE_CONSTANT (value))
  3575.     warning ("cast to pointer from integer of different size");
  3576.  
  3577.       ovalue = value;
  3578.       value = convert (type, value);
  3579.  
  3580.       /* Ignore any integer overflow caused by the cast.  */
  3581.       if (TREE_CODE (value) == INTEGER_CST)
  3582.     {
  3583.       TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  3584.       TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  3585.     }
  3586.     }
  3587.  
  3588.   /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant.  */
  3589.   if (pedantic && TREE_CODE (value) == INTEGER_CST
  3590.       && TREE_CODE (expr) == INTEGER_CST
  3591.       && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
  3592.     value = non_lvalue (value);
  3593.  
  3594.   /* If pedantic, don't let a cast be an lvalue.  */
  3595.   if (value == expr && pedantic)
  3596.     value = non_lvalue (value);
  3597.  
  3598.   return value;
  3599. }
  3600.  
  3601. /* Build an assignment expression of lvalue LHS from value RHS.
  3602.    MODIFYCODE is the code for a binary operator that we use
  3603.    to combine the old value of LHS with RHS to get the new value.
  3604.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  3605.  
  3606. tree
  3607. build_modify_expr (lhs, modifycode, rhs)
  3608.      tree lhs, rhs;
  3609.      enum tree_code modifycode;
  3610. {
  3611.   register tree result;
  3612.   tree newrhs;
  3613.   tree lhstype = TREE_TYPE (lhs);
  3614.   tree olhstype = lhstype;
  3615.  
  3616.   /* Types that aren't fully specified cannot be used in assignments.  */
  3617.   lhs = require_complete_type (lhs);
  3618.  
  3619.   /* Avoid duplicate error messages from operands that had errors.  */
  3620.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  3621.     return error_mark_node;
  3622.  
  3623.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3624.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  3625.      whose value is 0 to count as a null pointer constant.  */
  3626.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3627.     rhs = TREE_OPERAND (rhs, 0);
  3628.  
  3629.   newrhs = rhs;
  3630.  
  3631.   /* Handle control structure constructs used as "lvalues".  */
  3632.  
  3633.   switch (TREE_CODE (lhs))
  3634.     {
  3635.       /* Handle (a, b) used as an "lvalue".  */
  3636.     case COMPOUND_EXPR:
  3637.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3638.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
  3639.                   modifycode, rhs);
  3640.       if (TREE_CODE (newrhs) == ERROR_MARK)
  3641.     return error_mark_node;
  3642.       return build (COMPOUND_EXPR, lhstype,
  3643.             TREE_OPERAND (lhs, 0), newrhs);
  3644.  
  3645.       /* Handle (a ? b : c) used as an "lvalue".  */
  3646.     case COND_EXPR:
  3647.       pedantic_lvalue_warning (COND_EXPR);
  3648.       rhs = save_expr (rhs);
  3649.       {
  3650.     /* Produce (a ? (b = rhs) : (c = rhs))
  3651.        except that the RHS goes through a save-expr
  3652.        so the code to compute it is only emitted once.  */
  3653.     tree cond
  3654.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  3655.                     build_modify_expr (TREE_OPERAND (lhs, 1),
  3656.                                modifycode, rhs),
  3657.                     build_modify_expr (TREE_OPERAND (lhs, 2),
  3658.                                modifycode, rhs));
  3659.     if (TREE_CODE (cond) == ERROR_MARK)
  3660.       return cond;
  3661.     /* Make sure the code to compute the rhs comes out
  3662.        before the split.  */
  3663.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  3664.               /* But cast it to void to avoid an "unused" error.  */
  3665.               convert (void_type_node, rhs), cond);
  3666.       }
  3667.     }
  3668.  
  3669.   /* If a binary op has been requested, combine the old LHS value with the RHS
  3670.      producing the value we should actually store into the LHS.  */
  3671.  
  3672.   if (modifycode != NOP_EXPR)
  3673.     {
  3674.       lhs = stabilize_reference (lhs);
  3675.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  3676.     }
  3677.  
  3678.   /* Handle a cast used as an "lvalue".
  3679.      We have already performed any binary operator using the value as cast.
  3680.      Now convert the result to the cast type of the lhs,
  3681.      and then true type of the lhs and store it there;
  3682.      then convert result back to the cast type to be the value
  3683.      of the assignment.  */
  3684.  
  3685.   switch (TREE_CODE (lhs))
  3686.     {
  3687.     case NOP_EXPR:
  3688.     case CONVERT_EXPR:
  3689.     case FLOAT_EXPR:
  3690.     case FIX_TRUNC_EXPR:
  3691.     case FIX_FLOOR_EXPR:
  3692.     case FIX_ROUND_EXPR:
  3693.     case FIX_CEIL_EXPR:
  3694.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  3695.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  3696.     newrhs = default_conversion (newrhs);
  3697.       {
  3698.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  3699.     tree result;
  3700.     result = build_modify_expr (inner_lhs, NOP_EXPR,
  3701.                     convert (TREE_TYPE (inner_lhs),
  3702.                          convert (lhstype, newrhs)));
  3703.     if (TREE_CODE (result) == ERROR_MARK)
  3704.       return result;
  3705.     pedantic_lvalue_warning (CONVERT_EXPR);
  3706.     return convert (TREE_TYPE (lhs), result);
  3707.       }
  3708.     }
  3709.  
  3710.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  3711.      Reject anything strange now.  */
  3712.  
  3713.   if (!lvalue_or_else (lhs, "assignment"))
  3714.     return error_mark_node;
  3715.  
  3716.   /* Warn about storing in something that is `const'.  */
  3717.  
  3718.   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  3719.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  3720.        || TREE_CODE (lhstype) == UNION_TYPE)
  3721.       && C_TYPE_FIELDS_READONLY (lhstype)))
  3722.     readonly_warning (lhs, "assignment");
  3723.  
  3724.   /* If storing into a structure or union member,
  3725.      it has probably been given type `int'.
  3726.      Compute the type that would go with
  3727.      the actual amount of storage the member occupies.  */
  3728.  
  3729.   if (TREE_CODE (lhs) == COMPONENT_REF
  3730.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  3731.       || TREE_CODE (lhstype) == REAL_TYPE
  3732.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  3733.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  3734.  
  3735.   /* If storing in a field that is in actuality a short or narrower than one,
  3736.      we must store in the field in its actual type.  */
  3737.  
  3738.   if (lhstype != TREE_TYPE (lhs))
  3739.     {
  3740.       lhs = copy_node (lhs);
  3741.       TREE_TYPE (lhs) = lhstype;
  3742.     }
  3743.  
  3744.   /* Convert new value to destination type.  */
  3745.  
  3746.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  3747.                    NULL_TREE, NULL_TREE, 0);
  3748.   if (TREE_CODE (newrhs) == ERROR_MARK)
  3749.     return error_mark_node;
  3750.  
  3751.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  3752.   TREE_SIDE_EFFECTS (result) = 1;
  3753.  
  3754.   /* If we got the LHS in a different type for storing in,
  3755.      convert the result back to the nominal type of LHS
  3756.      so that the value we return always has the same type
  3757.      as the LHS argument.  */
  3758.  
  3759.   if (olhstype == TREE_TYPE (result))
  3760.     return result;
  3761.   return convert_for_assignment (olhstype, result, "assignment",
  3762.                  NULL_TREE, NULL_TREE, 0);
  3763. }
  3764.  
  3765. /* Convert value RHS to type TYPE as preparation for an assignment
  3766.    to an lvalue of type TYPE.
  3767.    The real work of conversion is done by `convert'.
  3768.    The purpose of this function is to generate error messages
  3769.    for assignments that are not allowed in C.
  3770.    ERRTYPE is a string to use in error messages:
  3771.    "assignment", "return", etc.  If it is null, this is parameter passing
  3772.    for a function call (and different error messages are output).  Otherwise,
  3773.    it may be a name stored in the spelling stack and interpreted by
  3774.    get_spelling.
  3775.  
  3776.    FUNNAME is the name of the function being called,
  3777.    as an IDENTIFIER_NODE, or null.
  3778.    PARMNUM is the number of the argument, for printing in error messages.  */
  3779.  
  3780. static tree
  3781. convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
  3782.      tree type, rhs;
  3783.      char *errtype;
  3784.      tree fundecl, funname;
  3785.      int parmnum;
  3786. {
  3787.   register enum tree_code codel = TREE_CODE (type);
  3788.   register tree rhstype;
  3789.   register enum tree_code coder;
  3790.  
  3791.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3792.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  3793.      whose value is 0 to count as a null pointer constant.  */
  3794.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3795.     rhs = TREE_OPERAND (rhs, 0);
  3796.  
  3797.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  3798.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  3799.     rhs = default_conversion (rhs);
  3800.  
  3801.   rhstype = TREE_TYPE (rhs);
  3802.   coder = TREE_CODE (rhstype);
  3803.  
  3804.   if (coder == ERROR_MARK)
  3805.     return error_mark_node;
  3806.  
  3807.   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  3808.     {
  3809.       overflow_warning (rhs);
  3810.       /* Check for Objective-C protocols.  This will issue a warning if
  3811.      there are protocol violations.  No need to use the return value.  */
  3812.       maybe_objc_comptypes (type, rhstype, 0);
  3813.       return rhs;
  3814.     }
  3815.  
  3816.   if (coder == VOID_TYPE)
  3817.     {
  3818.       error ("void value not ignored as it ought to be");
  3819.       return error_mark_node;
  3820.     }
  3821.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  3822.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
  3823.        || codel == COMPLEX_TYPE)
  3824.        &&
  3825.       (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
  3826.        || coder == COMPLEX_TYPE))
  3827.     return convert_and_check (type, rhs);
  3828.   /* Conversion to a union from its member types.  */
  3829.   else if (codel == UNION_TYPE)
  3830.     {
  3831.       tree memb_types;
  3832.       for (memb_types = TYPE_FIELDS (type); memb_types;
  3833.        memb_types = TREE_CHAIN (memb_types))
  3834.     {
  3835.       if (comptypes (TREE_TYPE (memb_types), TREE_TYPE (rhs)))
  3836.         {
  3837.           if (pedantic
  3838.           && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
  3839.         pedwarn ("ANSI C prohibits argument conversion to union type");
  3840.           return build1 (NOP_EXPR, type, rhs);
  3841.         }
  3842.       else if (coder == POINTER_TYPE
  3843.            && TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE)
  3844.         {
  3845.           tree memb_type = TREE_TYPE (memb_types);
  3846.           register tree ttl = TREE_TYPE (memb_type);
  3847.           register tree ttr = TREE_TYPE (rhstype);
  3848.  
  3849.           /* Any non-function converts to a [const][volatile] void *
  3850.          and vice versa; otherwise, targets must be the same.
  3851.          Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  3852.           if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  3853.           || TYPE_MAIN_VARIANT (ttr) == void_type_node
  3854.           || comp_target_types (memb_type, rhstype))
  3855.         {
  3856.           /* Const and volatile mean something different for function types,
  3857.              so the usual warnings are not appropriate.  */
  3858.           if (TREE_CODE (ttr) != FUNCTION_TYPE
  3859.               || TREE_CODE (ttl) != FUNCTION_TYPE)
  3860.             {
  3861.               if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  3862.             warn_for_assignment ("%s discards `const' from pointer target type",
  3863.                          get_spelling (errtype), funname, parmnum);
  3864.               if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  3865.             warn_for_assignment ("%s discards `volatile' from pointer target type",
  3866.                          get_spelling (errtype), funname, parmnum);
  3867.             }
  3868.           else
  3869.             {
  3870.               /* Because const and volatile on functions are restrictions
  3871.              that say the function will not do certain things,
  3872.              it is okay to use a const or volatile function
  3873.              where an ordinary one is wanted, but not vice-versa.  */
  3874.               if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
  3875.             warn_for_assignment ("%s makes `const *' function pointer from non-const",
  3876.                          get_spelling (errtype), funname, parmnum);
  3877.               if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
  3878.             warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
  3879.                          get_spelling (errtype), funname, parmnum);
  3880.             }
  3881.           if (pedantic
  3882.               && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
  3883.             pedwarn ("ANSI C prohibits argument conversion to union type");
  3884.           return build1 (NOP_EXPR, type, rhs);
  3885.         }
  3886.         }
  3887.     }
  3888.     }
  3889.   /* Conversions among pointers */
  3890.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  3891.     {
  3892.       register tree ttl = TREE_TYPE (type);
  3893.       register tree ttr = TREE_TYPE (rhstype);
  3894.  
  3895.       /* Any non-function converts to a [const][volatile] void *
  3896.      and vice versa; otherwise, targets must be the same.
  3897.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  3898.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  3899.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  3900.       || comp_target_types (type, rhstype)
  3901.       || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  3902.           == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
  3903.     {
  3904.       if (pedantic
  3905.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  3906.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  3907.           ||
  3908.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  3909.            /* Check TREE_CODE to catch cases like (void *) (char *) 0
  3910.               which are not ANSI null ptr constants.  */
  3911.            && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
  3912.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  3913.         warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
  3914.                  get_spelling (errtype), funname, parmnum);
  3915.       /* Const and volatile mean something different for function types,
  3916.          so the usual warnings are not appropriate.  */
  3917.       else if (TREE_CODE (ttr) != FUNCTION_TYPE
  3918.            || TREE_CODE (ttl) != FUNCTION_TYPE)
  3919.         {
  3920.           if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  3921.         warn_for_assignment ("%s discards `const' from pointer target type",
  3922.                      get_spelling (errtype), funname, parmnum);
  3923.           else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  3924.         warn_for_assignment ("%s discards `volatile' from pointer target type",
  3925.                      get_spelling (errtype), funname, parmnum);
  3926.           /* If this is not a case of ignoring a mismatch in signedness,
  3927.          no warning.  */
  3928.           else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  3929.                || TYPE_MAIN_VARIANT (ttr) == void_type_node
  3930.                || comp_target_types (type, rhstype))
  3931.         ;
  3932.           /* If there is a mismatch, do warn.  */
  3933.           else if (pedantic)
  3934.         warn_for_assignment ("pointer targets in %s differ in signedness",
  3935.                      get_spelling (errtype), funname, parmnum);
  3936.         }
  3937.       else
  3938.         {
  3939.           /* Because const and volatile on functions are restrictions
  3940.          that say the function will not do certain things,
  3941.          it is okay to use a const or volatile function
  3942.          where an ordinary one is wanted, but not vice-versa.  */
  3943.           if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
  3944.         warn_for_assignment ("%s makes `const *' function pointer from non-const",
  3945.                      get_spelling (errtype), funname, parmnum);
  3946.           if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
  3947.         warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
  3948.                      get_spelling (errtype), funname, parmnum);
  3949.         }
  3950.     }
  3951.       else
  3952.     warn_for_assignment ("%s from incompatible pointer type",
  3953.                  get_spelling (errtype), funname, parmnum);
  3954.       return convert (type, rhs);
  3955.     }
  3956.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  3957.     {
  3958.       /* An explicit constant 0 can convert to a pointer,
  3959.      or one that results from arithmetic, even including
  3960.      a cast to integer type.  */
  3961.       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
  3962.       &&
  3963.       ! (TREE_CODE (rhs) == NOP_EXPR
  3964.          && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
  3965.          && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
  3966.          && integer_zerop (TREE_OPERAND (rhs, 0))))
  3967.     {
  3968.       warn_for_assignment ("%s makes pointer from integer without a cast",
  3969.                    get_spelling (errtype), funname, parmnum);
  3970.       return convert (type, rhs);
  3971.     }
  3972.       return null_pointer_node;
  3973.     }
  3974.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  3975.     {
  3976.       warn_for_assignment ("%s makes integer from pointer without a cast",
  3977.                get_spelling (errtype), funname, parmnum);
  3978.       return convert (type, rhs);
  3979.     }
  3980.  
  3981.   if (!errtype)
  3982.     {
  3983.       if (funname)
  3984.      {
  3985.        tree selector = maybe_building_objc_message_expr ();
  3986.  
  3987.        if (selector && parmnum > 2)
  3988.          error ("incompatible type for argument %d of `%s'",
  3989.            parmnum - 2, IDENTIFIER_POINTER (selector));
  3990.        else
  3991.         error ("incompatible type for argument %d of `%s'",
  3992.            parmnum, IDENTIFIER_POINTER (funname));
  3993.     }
  3994.       else
  3995.     error ("incompatible type for argument %d of indirect function call",
  3996.            parmnum);
  3997.     }
  3998.   else
  3999.     error ("incompatible types in %s", get_spelling (errtype));
  4000.  
  4001.   return error_mark_node;
  4002. }
  4003.  
  4004. /* Print a warning using MSG.
  4005.    It gets OPNAME as its one parameter.
  4006.    If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
  4007.    FUNCTION and ARGNUM are handled specially if we are building an
  4008.    Objective-C selector.  */
  4009.  
  4010. int flag_next_runtime;
  4011.  
  4012. static void
  4013. warn_for_assignment (msg, opname, function, argnum)
  4014.      char *msg;
  4015.      char *opname;
  4016.      tree function;
  4017.      int argnum;
  4018. {
  4019.   static char argstring[] = "passing arg %d of `%s'";
  4020.   static char argnofun[] =  "passing arg %d";
  4021.  
  4022.   if (opname == 0)
  4023.     {
  4024.       tree selector = maybe_building_objc_message_expr ();
  4025.       
  4026.       if (selector && argnum > (flag_next_runtime ? 2 : 3))
  4027.     {
  4028.       function = selector;
  4029.       argnum -= (flag_next_runtime ? 2 : 3);
  4030.     }
  4031.       if (function)
  4032.     {
  4033.       /* Function name is known; supply it.  */
  4034.       opname = (char *) alloca (IDENTIFIER_LENGTH (function)
  4035.                     + sizeof (argstring) + 25 /*%d*/ + 1);
  4036.       sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
  4037.     }
  4038.       else
  4039.     {
  4040.       /* Function name unknown (call through ptr); just give arg number.  */
  4041.       opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1);
  4042.       sprintf (opname, argnofun, argnum);
  4043.     }
  4044.     }
  4045.   pedwarn (msg, opname);
  4046. }
  4047.  
  4048. /* Return nonzero if VALUE is a valid constant-valued expression
  4049.    for use in initializing a static variable; one that can be an
  4050.    element of a "constant" initializer.
  4051.  
  4052.    Return null_pointer_node if the value is absolute;
  4053.    if it is relocatable, return the variable that determines the relocation.
  4054.    We assume that VALUE has been folded as much as possible;
  4055.    therefore, we do not need to check for such things as
  4056.    arithmetic-combinations of integers.  */
  4057.  
  4058. static tree
  4059. initializer_constant_valid_p (value, endtype)
  4060.      tree value;
  4061.      tree endtype;
  4062. {
  4063.   switch (TREE_CODE (value))
  4064.     {
  4065.     case CONSTRUCTOR:
  4066.       if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
  4067.       && TREE_CONSTANT (value))
  4068.     return initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)));
  4069.     
  4070.       return TREE_STATIC (value) ? null_pointer_node : 0;
  4071.  
  4072.     case INTEGER_CST:
  4073.     case REAL_CST:
  4074.     case STRING_CST:
  4075.     case COMPLEX_CST:
  4076.       return null_pointer_node;
  4077.  
  4078.     case ADDR_EXPR:
  4079.       return TREE_OPERAND (value, 0);
  4080.  
  4081.     case NON_LVALUE_EXPR:
  4082.       return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4083.  
  4084.     case CONVERT_EXPR:
  4085.     case NOP_EXPR:
  4086. #ifdef NEXT_SEMANTICS
  4087.       /* Allow conversions between pointer types.  */
  4088.       if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
  4089.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
  4090.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4091. #endif
  4092.       /* Allow conversions between pointer types.  */
  4093.       if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
  4094.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  4095.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4096.       /* Allow conversions between real types.  */
  4097.       if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
  4098.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
  4099.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4100.       /* Allow length-preserving conversions between integer types.  */
  4101.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4102.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
  4103.       && tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (value)),
  4104.                  TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
  4105.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4106.       /* Allow conversions between integer types only if explicit value.  */
  4107.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4108.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
  4109.     {
  4110.       tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4111.                              endtype);
  4112.       if (inner == null_pointer_node)
  4113.         return null_pointer_node;
  4114.       return 0;
  4115.     }
  4116.       /* Allow (int) &foo provided int is as wide as a pointer.  */
  4117.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4118.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
  4119.       && ! tree_int_cst_lt (TYPE_SIZE (TREE_TYPE (value)),
  4120.                 TYPE_SIZE (TREE_TYPE (TREE_OPERAND (value, 0)))))
  4121.     return initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4122.                          endtype);
  4123.       /* Allow conversions to union types if the value inside is okay.  */
  4124.       if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
  4125.     return initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4126.                          endtype);
  4127.       return 0;
  4128.  
  4129.     case PLUS_EXPR:
  4130.       if (TREE_CODE (endtype) == INTEGER_TYPE
  4131.       && TYPE_PRECISION (endtype) < POINTER_SIZE)
  4132.     return 0;
  4133.       {
  4134.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4135.                             endtype);
  4136.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
  4137.                             endtype);
  4138.     /* If either term is absolute, use the other terms relocation.  */
  4139.     if (valid0 == null_pointer_node)
  4140.       return valid1;
  4141.     if (valid1 == null_pointer_node)
  4142.       return valid0;
  4143.     return 0;
  4144.       }
  4145.  
  4146.     case MINUS_EXPR:
  4147.       if (TREE_CODE (endtype) == INTEGER_TYPE
  4148.       && TYPE_PRECISION (endtype) < POINTER_SIZE)
  4149.     return 0;
  4150.       {
  4151.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4152.                             endtype);
  4153.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
  4154.                             endtype);
  4155.     /* Win if second argument is absolute.  */
  4156.     if (valid1 == null_pointer_node)
  4157.       return valid0;
  4158.     /* Win if both arguments have the same relocation.
  4159.        Then the value is absolute.  */
  4160.     if (valid0 == valid1)
  4161.       return null_pointer_node;
  4162.     return 0;
  4163.       }
  4164.     }
  4165.  
  4166.   return 0;
  4167. }
  4168.  
  4169. /* If VALUE is a compound expr all of whose expressions are constant, then
  4170.    return its value.  Otherwise, return error_mark_node.
  4171.  
  4172.    This is for handling COMPOUND_EXPRs as initializer elements
  4173.    which is allowed with a warning when -pedantic is specified.  */
  4174.  
  4175. static tree
  4176. valid_compound_expr_initializer (value, endtype)
  4177.      tree value;
  4178.      tree endtype;
  4179. {
  4180.   if (TREE_CODE (value) == COMPOUND_EXPR)
  4181.     {
  4182.       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
  4183.       == error_mark_node)
  4184.     return error_mark_node;
  4185.       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
  4186.                           endtype);
  4187.     }
  4188.   else if (! TREE_CONSTANT (value)
  4189.        && ! initializer_constant_valid_p (value, endtype))
  4190.     return error_mark_node;
  4191.   else
  4192.     return value;
  4193. }
  4194.  
  4195. /* Perform appropriate conversions on the initial value of a variable,
  4196.    store it in the declaration DECL,
  4197.    and print any error messages that are appropriate.
  4198.    If the init is invalid, store an ERROR_MARK.  */
  4199.  
  4200. void
  4201. store_init_value (decl, init)
  4202.      tree decl, init;
  4203. {
  4204.   register tree value, type;
  4205.  
  4206.   /* If variable's type was invalidly declared, just ignore it.  */
  4207.  
  4208.   type = TREE_TYPE (decl);
  4209.   if (TREE_CODE (type) == ERROR_MARK)
  4210.     return;
  4211.  
  4212.   /* Digest the specified initializer into an expression.  */
  4213.  
  4214.   value = digest_init (type, init, TREE_STATIC (decl),
  4215.                TREE_STATIC (decl) || pedantic);
  4216.  
  4217.   /* Store the expression if valid; else report error.  */
  4218.  
  4219. #if 0
  4220.   /* Note that this is the only place we can detect the error
  4221.      in a case such as   struct foo bar = (struct foo) { x, y };
  4222.      where there is one initial value which is a constructor expression.  */
  4223.   if (value == error_mark_node)
  4224.     ;
  4225.   else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
  4226.     {
  4227.       error ("initializer for static variable is not constant");
  4228.       value = error_mark_node;
  4229.     }
  4230.   else if (TREE_STATIC (decl)
  4231.        && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
  4232.     {
  4233.       error ("initializer for static variable uses complicated arithmetic");
  4234.       value = error_mark_node;
  4235.     }
  4236.   else
  4237.     {
  4238.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  4239.     {
  4240.       if (! TREE_CONSTANT (value))
  4241.         pedwarn ("aggregate initializer is not constant");
  4242.       else if (! TREE_STATIC (value))
  4243.         pedwarn ("aggregate initializer uses complicated arithmetic");
  4244.     }
  4245.     }
  4246. #endif
  4247.  
  4248.   DECL_INITIAL (decl) = value;
  4249.  
  4250.   /* ANSI wants warnings about out-of-range constant initializers.  */
  4251.   STRIP_TYPE_NOPS (value);
  4252.   constant_expression_warning (value);
  4253. }
  4254.  
  4255. /* Methods for storing and printing names for error messages.  */
  4256.  
  4257. /* Implement a spelling stack that allows components of a name to be pushed
  4258.    and popped.  Each element on the stack is this structure.  */
  4259.  
  4260. struct spelling
  4261. {
  4262.   int kind;
  4263.   union
  4264.     {
  4265.       int i;
  4266.       char *s;
  4267.     } u;
  4268. };
  4269.  
  4270. #define SPELLING_STRING 1
  4271. #define SPELLING_MEMBER 2
  4272. #define SPELLING_BOUNDS 3
  4273.  
  4274. static struct spelling *spelling;    /* Next stack element (unused).  */
  4275. static struct spelling *spelling_base;    /* Spelling stack base.  */
  4276. static int spelling_size;        /* Size of the spelling stack.  */
  4277.  
  4278. /* Macros to save and restore the spelling stack around push_... functions.
  4279.    Alternative to SAVE_SPELLING_STACK.  */
  4280.  
  4281. #define SPELLING_DEPTH() (spelling - spelling_base)
  4282. #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
  4283.  
  4284. /* Save and restore the spelling stack around arbitrary C code.  */
  4285.  
  4286. #define SAVE_SPELLING_DEPTH(code)        \
  4287. {                        \
  4288.   int __depth = SPELLING_DEPTH ();        \
  4289.   code;                        \
  4290.   RESTORE_SPELLING_DEPTH (__depth);        \
  4291. }
  4292.  
  4293. /* Push an element on the spelling stack with type KIND and assign VALUE
  4294.    to MEMBER.  */
  4295.  
  4296. #define PUSH_SPELLING(KIND, VALUE, MEMBER)                \
  4297. {                                    \
  4298.   int depth = SPELLING_DEPTH ();                    \
  4299.                                     \
  4300.   if (depth >= spelling_size)                        \
  4301.     {                                    \
  4302.       spelling_size += 10;                        \
  4303.       if (spelling_base == 0)                        \
  4304.     spelling_base                            \
  4305.       = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling));    \
  4306.       else                                \
  4307.         spelling_base                            \
  4308.       = (struct spelling *) xrealloc (spelling_base,        \
  4309.                       spelling_size * sizeof (struct spelling));    \
  4310.       RESTORE_SPELLING_DEPTH (depth);                    \
  4311.     }                                    \
  4312.                                     \
  4313.   spelling->kind = (KIND);                        \
  4314.   spelling->MEMBER = (VALUE);                        \
  4315.   spelling++;                                \
  4316. }
  4317.  
  4318. /* Push STRING on the stack.  Printed literally.  */
  4319.  
  4320. static void
  4321. push_string (string)
  4322.      char *string;
  4323. {
  4324.   PUSH_SPELLING (SPELLING_STRING, string, u.s);
  4325. }
  4326.  
  4327. /* Push a member name on the stack.  Printed as '.' STRING.  */
  4328.  
  4329. static void
  4330. push_member_name (decl)
  4331.      tree decl;
  4332.      
  4333. {
  4334.   char *string
  4335.     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
  4336.   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
  4337. }
  4338.  
  4339. /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
  4340.  
  4341. static void
  4342. push_array_bounds (bounds)
  4343.      int bounds;
  4344. {
  4345.   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
  4346. }
  4347.  
  4348. /* Compute the maximum size in bytes of the printed spelling.  */
  4349.  
  4350. static int
  4351. spelling_length ()
  4352. {
  4353.   register int size = 0;
  4354.   register struct spelling *p;
  4355.  
  4356.   for (p = spelling_base; p < spelling; p++)
  4357.     {
  4358.       if (p->kind == SPELLING_BOUNDS)
  4359.     size += 25;
  4360.       else
  4361.     size += strlen (p->u.s) + 1;
  4362.     }
  4363.  
  4364.   return size;
  4365. }
  4366.  
  4367. /* Print the spelling to BUFFER and return it.  */
  4368.  
  4369. static char *
  4370. print_spelling (buffer)
  4371.      register char *buffer;
  4372. {
  4373.   register char *d = buffer;
  4374.   register char *s;
  4375.   register struct spelling *p;
  4376.  
  4377.   for (p = spelling_base; p < spelling; p++)
  4378.     if (p->kind == SPELLING_BOUNDS)
  4379.       {
  4380.     sprintf (d, "[%d]", p->u.i);
  4381.     d += strlen (d);
  4382.       }
  4383.     else
  4384.       {
  4385.     if (p->kind == SPELLING_MEMBER)
  4386.       *d++ = '.';
  4387.     for (s = p->u.s; *d = *s++; d++)
  4388.       ;
  4389.       }
  4390.   *d++ = '\0';
  4391.   return buffer;
  4392. }
  4393.  
  4394. /* Provide a means to pass component names derived from the spelling stack.  */
  4395.  
  4396. char initialization_message;
  4397.  
  4398. /* Interpret the spelling of the given ERRTYPE message.  */
  4399.  
  4400. static char *
  4401. get_spelling (errtype)
  4402.      char *errtype;
  4403. {
  4404.   static char *buffer;
  4405.   static int size = -1;
  4406.  
  4407.   if (errtype == &initialization_message)
  4408.     {
  4409.       /* Avoid counting chars */
  4410.       static char message[] = "initialization of `%s'";
  4411.       register int needed = sizeof (message) + spelling_length () + 1;
  4412.       char *temp;
  4413.  
  4414.       if (size < 0)
  4415.     buffer = (char *) xmalloc (size = needed);
  4416.       if (needed > size)
  4417.     buffer = (char *) xrealloc (buffer, size = needed);
  4418.  
  4419.       temp = (char *) alloca (needed);
  4420.       sprintf (buffer, message, print_spelling (temp));
  4421.       return buffer;
  4422.     }
  4423.  
  4424.   return errtype;
  4425. }
  4426.  
  4427. /* Issue an error message for a bad initializer component.
  4428.    FORMAT describes the message.  OFWHAT is the name for the component.
  4429.    LOCAL is a format string for formatting the insertion of the name
  4430.    into the message.
  4431.  
  4432.    If OFWHAT is null, the component name is stored on the spelling stack.
  4433.    If the component name is a null string, then LOCAL is omitted entirely.  */
  4434.  
  4435. void
  4436. error_init (format, local, ofwhat)
  4437.      char *format, *local, *ofwhat;
  4438. {
  4439.   char *buffer;
  4440.  
  4441.   if (ofwhat == 0)
  4442.     ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
  4443.   buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
  4444.  
  4445.   if (*ofwhat)
  4446.     sprintf (buffer, local, ofwhat);
  4447.   else
  4448.     buffer[0] = 0;
  4449.  
  4450.   error (format, buffer);
  4451. }
  4452.  
  4453. /* Issue a pedantic warning for a bad initializer component.
  4454.    FORMAT describes the message.  OFWHAT is the name for the component.
  4455.    LOCAL is a format string for formatting the insertion of the name
  4456.    into the message.
  4457.  
  4458.    If OFWHAT is null, the component name is stored on the spelling stack.
  4459.    If the component name is a null string, then LOCAL is omitted entirely.  */
  4460.  
  4461. void
  4462. pedwarn_init (format, local, ofwhat)
  4463.      char *format, *local, *ofwhat;
  4464. {
  4465.   char *buffer;
  4466.  
  4467.   if (ofwhat == 0)
  4468.     ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
  4469.   buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
  4470.  
  4471.   if (*ofwhat)
  4472.     sprintf (buffer, local, ofwhat);
  4473.   else
  4474.     buffer[0] = 0;
  4475.  
  4476.   pedwarn (format, buffer);
  4477. }
  4478.  
  4479. /* Digest the parser output INIT as an initializer for type TYPE.
  4480.    Return a C expression of type TYPE to represent the initial value.
  4481.  
  4482.    The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
  4483.    if non-constant initializers or elements are seen.  CONSTRUCTOR_CONSTANT
  4484.    applies only to elements of constructors.  */
  4485.  
  4486. static tree
  4487. digest_init (type, init, require_constant, constructor_constant)
  4488.      tree type, init;
  4489.      int require_constant, constructor_constant;
  4490. {
  4491.   enum tree_code code = TREE_CODE (type);
  4492.   tree inside_init = init;
  4493.  
  4494.   if (init == error_mark_node)
  4495.     return init;
  4496.  
  4497.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  4498.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  4499.      whose value is 0 to count as a null pointer constant.  */
  4500.   if (TREE_CODE (init) == NON_LVALUE_EXPR)
  4501.     inside_init = TREE_OPERAND (init, 0);
  4502.  
  4503.   /* Initialization of an array of chars from a string constant
  4504.      optionally enclosed in braces.  */
  4505.  
  4506.   if (code == ARRAY_TYPE)
  4507.     {
  4508.       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
  4509.       if ((typ1 == char_type_node
  4510.        || typ1 == signed_char_type_node
  4511.        || typ1 == unsigned_char_type_node
  4512.        || typ1 == unsigned_wchar_type_node
  4513.        || typ1 == signed_wchar_type_node)
  4514.       && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
  4515.     {
  4516.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
  4517.              TYPE_MAIN_VARIANT (type)))
  4518.         return inside_init;
  4519.  
  4520.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
  4521.            != char_type_node)
  4522.           && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
  4523.         {
  4524.           error_init ("char-array%s initialized from wide string",
  4525.               " `%s'", NULL);
  4526.           return error_mark_node;
  4527.         }
  4528.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
  4529.            == char_type_node)
  4530.           && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
  4531.         {
  4532.           error_init ("int-array%s initialized from non-wide string",
  4533.               " `%s'", NULL);
  4534.           return error_mark_node;
  4535.         }
  4536.  
  4537.       TREE_TYPE (inside_init) = type;
  4538.       if (TYPE_DOMAIN (type) != 0
  4539.           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  4540.         {
  4541.           register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  4542.           size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  4543.           /* Subtract 1 (or sizeof (wchar_t))
  4544.          because it's ok to ignore the terminating null char
  4545.          that is counted in the length of the constant.  */
  4546.           if (size < TREE_STRING_LENGTH (inside_init)
  4547.           - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
  4548.              ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
  4549.              : 1))
  4550.         pedwarn_init (
  4551.           "initializer-string for array of chars%s is too long",
  4552.           " `%s'", NULL);
  4553.         }
  4554.       return inside_init;
  4555.     }
  4556.     }
  4557.  
  4558.   /* Any type can be initialized
  4559.      from an expression of the same type, optionally with braces.  */
  4560.  
  4561.   if (inside_init && TREE_TYPE (inside_init) != 0
  4562.       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
  4563.              TYPE_MAIN_VARIANT (type))
  4564.       || (code == ARRAY_TYPE
  4565.           && comptypes (TREE_TYPE (inside_init), type))
  4566.       || (code == POINTER_TYPE
  4567.           && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
  4568.           || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
  4569.           && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
  4570.                 TREE_TYPE (type)))))
  4571.     {
  4572.       if (code == POINTER_TYPE
  4573.       && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
  4574.           || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
  4575.     inside_init = default_conversion (inside_init);
  4576.       else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
  4577.            && TREE_CODE (inside_init) != CONSTRUCTOR)
  4578.     {
  4579.       error_init ("array%s initialized from non-constant array expression",
  4580.               " `%s'", NULL);
  4581.       return error_mark_node;
  4582.     }
  4583.  
  4584.       if (optimize && TREE_READONLY (inside_init)
  4585.       && TREE_CODE (inside_init) == VAR_DECL)
  4586.     inside_init = decl_constant_value (inside_init);
  4587.  
  4588.       /* Compound expressions can only occur here if -pedantic or
  4589.      -pedantic-errors is specified.  In the later case, we always want
  4590.      an error.  In the former case, we simply want a warning.  */
  4591.       if (require_constant && pedantic
  4592.       && TREE_CODE (inside_init) == COMPOUND_EXPR)
  4593.     {
  4594.       inside_init
  4595.         = valid_compound_expr_initializer (inside_init,
  4596.                            TREE_TYPE (inside_init));
  4597.       if (inside_init == error_mark_node)
  4598.         error_init ("initializer element%s is not constant",
  4599.             " for `%s'", NULL);
  4600.       else
  4601.         pedwarn_init ("initializer element%s is not constant",
  4602.               " for `%s'", NULL);
  4603.       if (flag_pedantic_errors)
  4604.         inside_init = error_mark_node;
  4605.     }
  4606.       else if (require_constant && ! TREE_CONSTANT (inside_init))
  4607.     {
  4608.       error_init ("initializer element%s is not constant",
  4609.               " for `%s'", NULL);
  4610.       inside_init = error_mark_node;
  4611.     }
  4612.       else if (require_constant
  4613.            && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
  4614.     {
  4615.       error_init ("initializer element%s is not computable at load time",
  4616.               " for `%s'", NULL);
  4617.       inside_init = error_mark_node;
  4618.     }
  4619.  
  4620.       return inside_init;
  4621.     }
  4622.  
  4623.   /* Handle scalar types, including conversions.  */
  4624.  
  4625.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  4626.       || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
  4627.     {
  4628.       /* Note that convert_for_assignment calls default_conversion
  4629.      for arrays and functions.  We must not call it in the
  4630.      case where inside_init is a null pointer constant.  */
  4631.       inside_init
  4632.     = convert_for_assignment (type, init, "initialization",
  4633.                   NULL_TREE, NULL_TREE, 0);
  4634.  
  4635.       if (require_constant && ! TREE_CONSTANT (inside_init))
  4636.     {
  4637.       error_init ("initializer element%s is not constant",
  4638.               " for `%s'", NULL);
  4639.       inside_init = error_mark_node;
  4640.     }
  4641.       else if (require_constant
  4642.            && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
  4643.     {
  4644.       error_init ("initializer element%s is not computable at load time",
  4645.               " for `%s'", NULL);
  4646.       inside_init = error_mark_node;
  4647.     }
  4648.  
  4649.       return inside_init;
  4650.     }
  4651.  
  4652.   /* Come here only for records and arrays.  */
  4653.  
  4654.   if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4655.     {
  4656.       error_init ("variable-sized object%s may not be initialized",
  4657.           " `%s'", NULL);
  4658.       return error_mark_node;
  4659.     }
  4660.  
  4661.   /* Traditionally, you can write  struct foo x = 0;
  4662.      and it initializes the first element of x to 0.  */
  4663.   if (flag_traditional)
  4664.     {
  4665.       tree top = 0, prev = 0;
  4666.       while (TREE_CODE (type) == RECORD_TYPE
  4667.          || TREE_CODE (type) == ARRAY_TYPE
  4668.          || TREE_CODE (type) == QUAL_UNION_TYPE
  4669.          || TREE_CODE (type) == UNION_TYPE)
  4670.     {
  4671.       tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
  4672.       if (prev == 0)
  4673.         top = temp;
  4674.       else
  4675.         TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
  4676.       prev = temp;
  4677.       if (TREE_CODE (type) == ARRAY_TYPE)
  4678.         type = TREE_TYPE (type);
  4679.       else if (TYPE_FIELDS (type))
  4680.         type = TREE_TYPE (TYPE_FIELDS (type));
  4681.       else
  4682.         {
  4683.           error_init ("invalid initializer%s", " for `%s'", NULL);
  4684.           return error_mark_node;
  4685.         }
  4686.     }
  4687.       TREE_OPERAND (prev, 1)
  4688.     = build_tree_list (NULL_TREE,
  4689.                digest_init (type, init, require_constant,
  4690.                     constructor_constant));
  4691.       return top;
  4692.     }
  4693.   error_init ("invalid initializer%s", " for `%s'", NULL);
  4694.   return error_mark_node;
  4695. }
  4696.  
  4697. /* Handle initializers that use braces.  */
  4698.  
  4699. static void output_init_element ();
  4700. static void output_pending_init_elements ();
  4701. static void check_init_type_bitfields ();
  4702.  
  4703. /* Type of object we are accumulating a constructor for.
  4704.    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
  4705. static tree constructor_type;
  4706.  
  4707. /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
  4708.    left to fill.  */
  4709. static tree constructor_fields;
  4710.  
  4711. /* For an ARRAY_TYPE, this is the specified index
  4712.    at which to store the next element we get.
  4713.    This is a special INTEGER_CST node that we modify in place.  */
  4714. static tree constructor_index;
  4715.  
  4716. /* For an ARRAY_TYPE, this is the end index of the range
  4717.    to intitialize with the next element, or NULL in the ordinary case
  4718.    where the element is used just once.  */
  4719. static tree constructor_range_end;
  4720.  
  4721. /* For an ARRAY_TYPE, this is the maximum index.  */
  4722. static tree constructor_max_index;
  4723.  
  4724. /* For a RECORD_TYPE, this is the first field not yet written out.  */
  4725. static tree constructor_unfilled_fields;
  4726.  
  4727. /* For an ARRAY_TYPE, this is the index of the first element
  4728.    not yet written out.
  4729.    This is a special INTEGER_CST node that we modify in place.  */
  4730. static tree constructor_unfilled_index;
  4731.  
  4732. /* In a RECORD_TYPE, the byte index of the next consecutive field.
  4733.    This is so we can generate gaps between fields, when appropriate.
  4734.    This is a special INTEGER_CST node that we modify in place.  */
  4735. static tree constructor_bit_index;
  4736.  
  4737. /* If we are saving up the elements rather than allocating them,
  4738.    this is the list of elements so far (in reverse order,
  4739.    most recent first).  */
  4740. static tree constructor_elements;
  4741.  
  4742. /* 1 if so far this constructor's elements are all compile-time constants.  */
  4743. static int constructor_constant;
  4744.  
  4745. /* 1 if so far this constructor's elements are all valid address constants.  */
  4746. static int constructor_simple;
  4747.  
  4748. /* 1 if this constructor is erroneous so far.  */
  4749. static int constructor_erroneous;
  4750.  
  4751. /* 1 if have called defer_addressed_constants.  */
  4752. static int constructor_subconstants_deferred;
  4753.  
  4754. /* List of pending elements at this constructor level.
  4755.    These are elements encountered out of order
  4756.    which belong at places we haven't reached yet in actually
  4757.    writing the output.  */
  4758. static tree constructor_pending_elts;
  4759.  
  4760. /* The SPELLING_DEPTH of this constructor.  */
  4761. static int constructor_depth;
  4762.  
  4763. /* 0 if implicitly pushing constructor levels is allowed.  */
  4764. int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
  4765.  
  4766. /* 1 if this constructor level was entered implicitly.  */
  4767. static int constructor_implicit;
  4768.  
  4769. static int require_constant_value;
  4770. static int require_constant_elements;
  4771.  
  4772. /* 1 if it is ok to output this constructor as we read it.
  4773.    0 means must accumulate a CONSTRUCTOR expression.  */
  4774. static int constructor_incremental;
  4775.  
  4776. /* DECL node for which an initializer is being read.
  4777.    0 means we are reading a constructor expression
  4778.    such as (struct foo) {...}.  */
  4779. static tree constructor_decl;
  4780.  
  4781. /* start_init saves the ASMSPEC arg here for really_start_incremental_init.  */
  4782. static char *constructor_asmspec;
  4783.  
  4784. /* Nonzero if this is an initializer for a top-level decl.  */
  4785. static int constructor_top_level;
  4786.  
  4787. /* When we finish reading a constructor expression
  4788.    (constructor_decl is 0), the CONSTRUCTOR goes here.  */
  4789. static tree constructor_result;
  4790.  
  4791. /* This stack has a level for each implicit or explicit level of
  4792.    structuring in the initializer, including the outermost one.  It
  4793.    saves the values of most of the variables above.  */
  4794.  
  4795. struct constructor_stack
  4796. {
  4797.   struct constructor_stack *next;
  4798.   tree type;
  4799.   tree fields;
  4800.   tree index;
  4801.   tree range_end;
  4802.   tree max_index;
  4803.   tree unfilled_index;
  4804.   tree unfilled_fields;
  4805.   tree bit_index;
  4806.   tree elements;
  4807.   int offset;
  4808.   tree pending_elts;
  4809.   int depth;
  4810.   /* If nonzero, this value should replace the entire
  4811.      constructor at this level.  */
  4812.   tree replacement_value;
  4813.   char constant;
  4814.   char simple;
  4815.   char implicit;
  4816.   char incremental;
  4817.   char erroneous;
  4818.   char outer;
  4819. };
  4820.  
  4821. struct constructor_stack *constructor_stack;
  4822.  
  4823. /* This stack records separate initializers that are nested.
  4824.    Nested initializers can't happen in ANSI C, but GNU C allows them
  4825.    in cases like { ... (struct foo) { ... } ... }.  */
  4826.  
  4827. struct initializer_stack
  4828. {
  4829.   struct initializer_stack *next;
  4830.   tree decl;
  4831.   char *asmspec;
  4832.   struct constructor_stack *constructor_stack;
  4833.   tree elements;
  4834.   struct spelling *spelling;
  4835.   struct spelling *spelling_base;
  4836.   int spelling_size;
  4837.   char top_level;
  4838.   char incremental;
  4839.   char require_constant_value;
  4840.   char require_constant_elements;
  4841.   char deferred;
  4842. };
  4843.  
  4844. struct initializer_stack *initializer_stack;
  4845.  
  4846. /* Prepare to parse and output the initializer for variable DECL.  */
  4847.  
  4848. void
  4849. start_init (decl, asmspec_tree, top_level)
  4850.      tree decl;
  4851.      tree asmspec_tree;
  4852.      int top_level;
  4853. {
  4854.   char *locus;
  4855.   struct initializer_stack *p
  4856.     = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
  4857.   char *asmspec = 0;
  4858.  
  4859.   if (asmspec_tree)
  4860.     asmspec = TREE_STRING_POINTER (asmspec_tree);
  4861.  
  4862.   p->decl = constructor_decl;
  4863.   p->asmspec = constructor_asmspec;
  4864.   p->incremental = constructor_incremental;
  4865.   p->require_constant_value = require_constant_value;
  4866.   p->require_constant_elements = require_constant_elements;
  4867.   p->constructor_stack = constructor_stack;
  4868.   p->elements = constructor_elements;
  4869.   p->spelling = spelling;
  4870.   p->spelling_base = spelling_base;
  4871.   p->spelling_size = spelling_size;
  4872.   p->deferred = constructor_subconstants_deferred;
  4873.   p->top_level = constructor_top_level;
  4874.   p->next = initializer_stack;
  4875.   initializer_stack = p;
  4876.  
  4877.   constructor_decl = decl;
  4878.   constructor_incremental = top_level;
  4879.   constructor_asmspec = asmspec;
  4880.   constructor_subconstants_deferred = 0;
  4881.   constructor_top_level = top_level;
  4882.  
  4883.   if (decl != 0)
  4884.     {
  4885.       require_constant_value = TREE_STATIC (decl);
  4886.       require_constant_elements
  4887.     = ((TREE_STATIC (decl) || pedantic)
  4888.        /* For a scalar, you can always use any value to initialize,
  4889.           even within braces.  */
  4890.        && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  4891.            || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  4892.            || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
  4893.            || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
  4894.       locus = IDENTIFIER_POINTER (DECL_NAME (decl));
  4895.       constructor_incremental |= TREE_STATIC (decl);
  4896.     }
  4897.   else
  4898.     {
  4899.       require_constant_value = 0;
  4900.       require_constant_elements = 0;
  4901.       locus = "(anonymous)";
  4902.     }
  4903.  
  4904.   constructor_stack = 0;
  4905.  
  4906.   spelling_base = 0;
  4907.   spelling_size = 0;
  4908.   RESTORE_SPELLING_DEPTH (0);
  4909.  
  4910.   if (locus)
  4911.     push_string (locus);
  4912. }
  4913.  
  4914. void
  4915. finish_init ()
  4916. {
  4917.   struct initializer_stack *p = initializer_stack;
  4918.  
  4919.   /* Output subconstants (string constants, usually)
  4920.      that were referenced within this initializer and saved up.
  4921.      Must do this if and only if we called defer_addressed_constants.  */
  4922.   if (constructor_subconstants_deferred)
  4923.     output_deferred_addressed_constants ();
  4924.  
  4925.   /* Free the whole constructor stack of this initializer.  */
  4926.   while (constructor_stack)
  4927.     {
  4928.       struct constructor_stack *q = constructor_stack;
  4929.       constructor_stack = q->next;
  4930.       free (q);
  4931.     }
  4932.  
  4933.   /* Pop back to the data of the outer initializer (if any).  */
  4934.   constructor_decl = p->decl;
  4935.   constructor_asmspec = p->asmspec;
  4936.   constructor_incremental = p->incremental;
  4937.   require_constant_value = p->require_constant_value;
  4938.   require_constant_elements = p->require_constant_elements;
  4939.   constructor_stack = p->constructor_stack;
  4940.   constructor_elements = p->elements;
  4941.   spelling = p->spelling;
  4942.   spelling_base = p->spelling_base;
  4943.   spelling_size = p->spelling_size;
  4944.   constructor_subconstants_deferred = p->deferred;
  4945.   constructor_top_level = p->top_level;
  4946.   initializer_stack = p->next;
  4947.   free (p);
  4948. }
  4949.  
  4950. /* Call here when we see the initializer is surrounded by braces.
  4951.    This is instead of a call to push_init_level;
  4952.    it is matched by a call to pop_init_level.
  4953.  
  4954.    TYPE is the type to initialize, for a constructor expression.
  4955.    For an initializer for a decl, TYPE is zero.  */
  4956.  
  4957. void
  4958. really_start_incremental_init (type)
  4959.      tree type;
  4960. {
  4961.   struct constructor_stack *p
  4962.     = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
  4963.  
  4964.   if (type == 0)
  4965.     type = TREE_TYPE (constructor_decl);
  4966.  
  4967.   /* Turn off constructor_incremental if type is a struct with bitfields.
  4968.      Do this before the first push, so that the corrected value
  4969.      is available in finish_init.  */
  4970.   check_init_type_bitfields (type);
  4971.  
  4972.   p->type = constructor_type;
  4973.   p->fields = constructor_fields;
  4974.   p->index = constructor_index;
  4975.   p->range_end = constructor_range_end;
  4976.   p->max_index = constructor_max_index;
  4977.   p->unfilled_index = constructor_unfilled_index;
  4978.   p->unfilled_fields = constructor_unfilled_fields;
  4979.   p->bit_index = constructor_bit_index;
  4980.   p->elements = 0;
  4981.   p->constant = constructor_constant;
  4982.   p->simple = constructor_simple;
  4983.   p->erroneous = constructor_erroneous;
  4984.   p->pending_elts = constructor_pending_elts;
  4985.   p->depth = constructor_depth;
  4986.   p->replacement_value = 0;
  4987.   p->implicit = 0;
  4988.   p->incremental = constructor_incremental;
  4989.   p->outer = 0;
  4990.   p->next = 0;
  4991.   constructor_stack = p;
  4992.  
  4993.   constructor_constant = 1;
  4994.   constructor_simple = 1;
  4995.   constructor_depth = SPELLING_DEPTH ();
  4996.   constructor_elements = 0;
  4997.   constructor_pending_elts = 0;
  4998.   constructor_type = type;
  4999.  
  5000.   if (TREE_CODE (constructor_type) == RECORD_TYPE
  5001.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5002.     {
  5003.       constructor_fields = TYPE_FIELDS (constructor_type);
  5004.       /* Skip any nameless bit fields atthe beginning.  */
  5005.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  5006.          && DECL_NAME (constructor_fields) == 0)
  5007.     constructor_fields = TREE_CHAIN (constructor_fields);
  5008.       constructor_unfilled_fields = constructor_fields;
  5009.       constructor_bit_index = copy_node (integer_zero_node);
  5010.     }
  5011.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5012.     {
  5013.       constructor_range_end = 0;
  5014.       if (TYPE_DOMAIN (constructor_type))
  5015.     {
  5016.       constructor_max_index
  5017.         = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
  5018.       constructor_index
  5019.         = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
  5020.     }
  5021.       else
  5022.     constructor_index = copy_node (integer_zero_node);
  5023.       constructor_unfilled_index = copy_node (constructor_index);
  5024.     }
  5025.   else
  5026.     {
  5027.       /* Handle the case of int x = {5}; */
  5028.       constructor_fields = constructor_type;
  5029.       constructor_unfilled_fields = constructor_type;
  5030.     }
  5031.  
  5032.   if (constructor_incremental)
  5033.     {
  5034.       int momentary = suspend_momentary ();
  5035.       push_obstacks_nochange ();
  5036.       if (TREE_PERMANENT (constructor_decl))
  5037.     end_temporary_allocation ();
  5038.       make_decl_rtl (constructor_decl, constructor_asmspec,
  5039.              constructor_top_level);
  5040.       assemble_variable (constructor_decl, constructor_top_level, 0, 1);
  5041.       pop_obstacks ();
  5042.       resume_momentary (momentary);
  5043.     }
  5044.  
  5045.   if (constructor_incremental)
  5046.     {
  5047.       defer_addressed_constants ();
  5048.       constructor_subconstants_deferred = 1;
  5049.     }
  5050. }
  5051.  
  5052. /* 
  5053.    Answer if DECL is currently not initialized, but will be
  5054.    shortly.  That is, if we're in the middle of initializing it.
  5055.  */
  5056.  
  5057. int
  5058. lang_decl_being_initialized (decl)
  5059.      tree decl;
  5060. {
  5061.   struct initializer_stack *p;
  5062.   if (!decl)
  5063.     return 0;
  5064.   if (decl == constructor_decl)
  5065.     return 1;
  5066.   for (p = initializer_stack; p; p = p->next)
  5067.     if (decl == p->decl)
  5068.       return 1;
  5069.   return 0;
  5070. }
  5071.  
  5072.  
  5073. /* Push down into a subobject, for initialization.
  5074.    If this is for an explicit set of braces, IMPLICIT is 0.
  5075.    If it is because the next element belongs at a lower level,
  5076.    IMPLICIT is 1.  */
  5077.  
  5078. void
  5079. push_init_level (implicit)
  5080.      int implicit;
  5081. {
  5082.   struct constructor_stack *p;
  5083.  
  5084.   /* If we've exhausted any levels that didn't have braces,
  5085.      pop them now.  */
  5086.   while (constructor_stack->implicit)
  5087.     {
  5088.       if ((TREE_CODE (constructor_type) == RECORD_TYPE
  5089.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5090.       && constructor_fields == 0)
  5091.     process_init_element (pop_init_level (1));
  5092.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5093.            && tree_int_cst_lt (constructor_max_index, constructor_index))
  5094.     process_init_element (pop_init_level (1));
  5095.       else
  5096.     break;
  5097.     }
  5098.  
  5099.   /* Structure elements may require alignment.  Do this now
  5100.      if necessary for the subaggregate.  */
  5101.   if (constructor_incremental && TREE_CODE (constructor_type) == RECORD_TYPE
  5102.       && constructor_fields)
  5103.     {
  5104.       /* Advance to offset of this element.  */
  5105.       if (! tree_int_cst_equal (constructor_bit_index,
  5106.                 DECL_FIELD_BITPOS (constructor_fields)))
  5107.     {
  5108.       int next = (TREE_INT_CST_LOW
  5109.               (DECL_FIELD_BITPOS (constructor_fields))
  5110.               / BITS_PER_UNIT);
  5111.       int here = (TREE_INT_CST_LOW (constructor_bit_index)
  5112.               / BITS_PER_UNIT);
  5113.  
  5114.       assemble_zeros (next - here);
  5115.     }
  5116.     }
  5117.  
  5118.   p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
  5119.   p->type = constructor_type;
  5120.   p->fields = constructor_fields;
  5121.   p->index = constructor_index;
  5122.   p->range_end = constructor_range_end;
  5123.   p->max_index = constructor_max_index;
  5124.   p->unfilled_index = constructor_unfilled_index;
  5125.   p->unfilled_fields = constructor_unfilled_fields;
  5126.   p->bit_index = constructor_bit_index;
  5127.   p->elements = constructor_elements;
  5128.   p->constant = constructor_constant;
  5129.   p->simple = constructor_simple;
  5130.   p->erroneous = constructor_erroneous;
  5131.   p->pending_elts = constructor_pending_elts;
  5132.   p->depth = constructor_depth;
  5133.   p->replacement_value = 0;
  5134.   p->implicit = implicit;
  5135.   p->incremental = constructor_incremental;
  5136.   p->outer = 0;
  5137.   p->next = constructor_stack;
  5138.   constructor_stack = p;
  5139.  
  5140.   constructor_constant = 1;
  5141.   constructor_simple = 1;
  5142.   constructor_depth = SPELLING_DEPTH ();
  5143.   constructor_elements = 0;
  5144.   constructor_pending_elts = 0;
  5145.  
  5146.   /* Don't die if an entire brace-pair level is superfluous
  5147.      in the containing level.  */
  5148.   if (constructor_type == 0)
  5149.     ;
  5150.   else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5151.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5152.     {
  5153.       /* Don't die if there are extra init elts at the end.  */
  5154.       if (constructor_fields == 0)
  5155.     constructor_type = 0;
  5156.       else
  5157.     {
  5158.       constructor_type = TREE_TYPE (constructor_fields);
  5159.       push_member_name (constructor_fields);
  5160.     }
  5161.     }
  5162.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5163.     {
  5164.       constructor_type = TREE_TYPE (constructor_type);
  5165.       push_array_bounds (TREE_INT_CST_LOW (constructor_index));
  5166.     }
  5167.  
  5168.   /* Turn off constructor_incremental if type is a struct with bitfields.  */
  5169.   if (constructor_type != 0)
  5170.     check_init_type_bitfields (constructor_type);
  5171.  
  5172.   if (constructor_type == 0)
  5173.     {
  5174.       error_init ("extra brace group at end of initializer%s",
  5175.           " for `%s'", NULL);
  5176.       constructor_fields = 0;
  5177.       constructor_unfilled_fields = 0;
  5178.     }
  5179.   else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5180.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5181.     {
  5182.       constructor_fields = TYPE_FIELDS (constructor_type);
  5183.       /* Skip any nameless bit fields atthe beginning.  */
  5184.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  5185.          && DECL_NAME (constructor_fields) == 0)
  5186.     constructor_fields = TREE_CHAIN (constructor_fields);
  5187.       constructor_unfilled_fields = constructor_fields;
  5188.       constructor_bit_index = copy_node (integer_zero_node);
  5189.     }
  5190.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5191.     {
  5192.       constructor_range_end = 0;
  5193.       if (TYPE_DOMAIN (constructor_type))
  5194.     {
  5195.       constructor_max_index
  5196.         = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
  5197.       constructor_index
  5198.         = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
  5199.     }
  5200.       else
  5201.     constructor_index = copy_node (integer_zero_node);
  5202.       constructor_unfilled_index = copy_node (constructor_index);
  5203.     }
  5204.   else
  5205.     {
  5206.       warning ("braces around scalar initializer");
  5207.       constructor_fields = constructor_type;
  5208.       constructor_unfilled_fields = constructor_type;
  5209.     }
  5210. }
  5211.  
  5212. /* Don't read a struct incrementally if it has any bitfields,
  5213.    because the incremental reading code doesn't know how to
  5214.    handle bitfields yet.  */
  5215.  
  5216. static void
  5217. check_init_type_bitfields (type)
  5218.      tree type;
  5219. {
  5220.   if (TREE_CODE (type) == RECORD_TYPE)
  5221.     {
  5222.       tree tail;
  5223.       for (tail = TYPE_FIELDS (type); tail;
  5224.        tail = TREE_CHAIN (tail))
  5225.     {
  5226.       if (DECL_BIT_FIELD (tail)
  5227.           /* This catches cases like `int foo : 8;'.  */
  5228.           || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail)))
  5229.         {
  5230.           constructor_incremental = 0;
  5231.           break;
  5232.         }
  5233.  
  5234.       check_init_type_bitfields (TREE_TYPE (tail));
  5235.     }
  5236.     }
  5237.  
  5238.   else if (TREE_CODE (type) == ARRAY_TYPE)
  5239.     check_init_type_bitfields (TREE_TYPE (type));
  5240. }
  5241.  
  5242. /* At the end of an implicit or explicit brace level, 
  5243.    finish up that level of constructor.
  5244.    If we were outputting the elements as they are read, return 0
  5245.    from inner levels (process_init_element ignores that),
  5246.    but return error_mark_node from the outermost level
  5247.    (that's what we want to put in DECL_INITIAL).
  5248.    Otherwise, return a CONSTRUCTOR expression.  */
  5249.  
  5250. tree
  5251. pop_init_level (implicit)
  5252.      int implicit;
  5253. {
  5254.   struct constructor_stack *p;
  5255.   int size;
  5256.   tree constructor = 0;
  5257.  
  5258.   if (implicit == 0)
  5259.     {
  5260.       /* When we come to an explicit close brace,
  5261.      pop any inner levels that didn't have explicit braces.  */
  5262.       while (constructor_stack->implicit)
  5263.     process_init_element (pop_init_level (1));
  5264.     }
  5265.  
  5266.   p = constructor_stack;
  5267.  
  5268.   if (constructor_type != 0)
  5269.     size = int_size_in_bytes (constructor_type);
  5270.  
  5271.   /* Now output all pending elements.  */
  5272.   output_pending_init_elements (1);
  5273.  
  5274. #if 0 /* c-parse.in warns about {}.  */
  5275.   /* In ANSI, each brace level must have at least one element.  */
  5276.   if (! implicit && pedantic
  5277.       && (TREE_CODE (constructor_type) == ARRAY_TYPE
  5278.       ? integer_zerop (constructor_unfilled_index)
  5279.       : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
  5280.     pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
  5281. #endif
  5282.  
  5283.   /* Pad out the end of the structure.  */
  5284.   
  5285.   if (p->replacement_value)
  5286.     {
  5287.       /* If this closes a superfluous brace pair,
  5288.      just pass out the element between them.  */
  5289.       constructor = p->replacement_value;
  5290.       /* If this is the top level thing within the initializer,
  5291.      and it's for a variable, then since we already called
  5292.      assemble_variable, we must output the value now.  */
  5293.       if (p->next == 0 && constructor_decl != 0
  5294.       && constructor_incremental)
  5295.     {
  5296.       constructor = digest_init (constructor_type, constructor,
  5297.                      0, 0);
  5298.  
  5299.       /* If initializing an array of unknown size,
  5300.          determine the size now.  */
  5301.       if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5302.           && TYPE_DOMAIN (constructor_type) == 0)
  5303.         {
  5304.           int failure;
  5305.           int momentary_p;
  5306.  
  5307.           push_obstacks_nochange ();
  5308.           if (TREE_PERMANENT (constructor_type))
  5309.         end_temporary_allocation ();
  5310.  
  5311.           momentary_p = suspend_momentary (); 
  5312.  
  5313.           /* We shouldn't have an incomplete array type within
  5314.          some other type.  */
  5315.           if (constructor_stack->next)
  5316.         abort ();
  5317.  
  5318.           failure
  5319.         = complete_array_type (constructor_type,
  5320.                        constructor, 0);
  5321.           if (failure)
  5322.         abort ();
  5323.  
  5324.           size = int_size_in_bytes (constructor_type);
  5325.           resume_momentary (momentary_p);
  5326.           pop_obstacks ();
  5327.         }
  5328.  
  5329.       output_constant (constructor, size);
  5330.     }
  5331.     }
  5332.   else if (constructor_type == 0)
  5333.     ;
  5334.   else if (TREE_CODE (constructor_type) != RECORD_TYPE
  5335.        && TREE_CODE (constructor_type) != UNION_TYPE
  5336.        && TREE_CODE (constructor_type) != ARRAY_TYPE
  5337.        && ! constructor_incremental)
  5338.     {
  5339.       /* A nonincremental scalar initializer--just return
  5340.      the element, after verifying there is just one.  */
  5341.       if (constructor_elements == 0)
  5342.     {
  5343.       error_init ("empty scalar initializer%s",
  5344.               " for `%s'", NULL);
  5345.       constructor = error_mark_node;
  5346.     }
  5347.       else if (TREE_CHAIN (constructor_elements) != 0)
  5348.     {
  5349.       error_init ("extra elements in scalar initializer%s",
  5350.               " for `%s'", NULL);
  5351.       constructor = TREE_VALUE (constructor_elements);
  5352.     }
  5353.       else
  5354.     constructor = TREE_VALUE (constructor_elements);
  5355.     }
  5356.   else if (! constructor_incremental)
  5357.     {
  5358.       if (constructor_erroneous)
  5359.     constructor = error_mark_node;
  5360.       else
  5361.     {
  5362.       int momentary = suspend_momentary ();
  5363.  
  5364.       constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
  5365.                    nreverse (constructor_elements));
  5366.       if (constructor_constant)
  5367.         TREE_CONSTANT (constructor) = 1;
  5368.       if (constructor_constant && constructor_simple)
  5369.         TREE_STATIC (constructor) = 1;
  5370.  
  5371.       resume_momentary (momentary);
  5372.     }
  5373.     }
  5374.   else
  5375.     {
  5376.       tree filled;
  5377.       int momentary = suspend_momentary ();
  5378.  
  5379.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5380.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5381.     {
  5382.       /* Find the offset of the end of that field.  */
  5383.       filled = size_binop (CEIL_DIV_EXPR,
  5384.                    constructor_bit_index,
  5385.                    size_int (BITS_PER_UNIT));
  5386.     }
  5387.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5388.     {
  5389.       /* If initializing an array of unknown size,
  5390.          determine the size now.  */
  5391.       if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5392.           && TYPE_DOMAIN (constructor_type) == 0)
  5393.         {
  5394.           tree maxindex
  5395.         = size_binop (MINUS_EXPR,
  5396.                   constructor_unfilled_index,
  5397.                   integer_one_node);
  5398.  
  5399.           push_obstacks_nochange ();
  5400.           if (TREE_PERMANENT (constructor_type))
  5401.         end_temporary_allocation ();
  5402.           maxindex = copy_node (maxindex);
  5403.           TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
  5404.           TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
  5405.  
  5406.           if (pedantic
  5407.           && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)),
  5408.                       integer_zero_node))
  5409.         error_with_decl (constructor_decl, "zero-size array `%s'");
  5410.           layout_type (constructor_type);
  5411.           size = int_size_in_bytes (constructor_type);
  5412.           pop_obstacks ();
  5413.         }
  5414.  
  5415.       filled = size_binop (MULT_EXPR, constructor_unfilled_index,
  5416.                    size_in_bytes (TREE_TYPE (constructor_type)));
  5417.     }
  5418.       else
  5419.     filled = 0;
  5420.  
  5421.       if (filled != 0)
  5422.     assemble_zeros (size - TREE_INT_CST_LOW (filled));
  5423.  
  5424.       resume_momentary (momentary);
  5425.     }
  5426.  
  5427.       
  5428.   constructor_type = p->type;
  5429.   constructor_fields = p->fields;
  5430.   constructor_index = p->index;
  5431.   constructor_range_end = p->range_end;
  5432.   constructor_max_index = p->max_index;
  5433.   constructor_unfilled_index = p->unfilled_index;
  5434.   constructor_unfilled_fields = p->unfilled_fields;
  5435.   constructor_bit_index = p->bit_index;
  5436.   constructor_elements = p->elements;
  5437.   constructor_constant = p->constant;
  5438.   constructor_simple = p->simple;
  5439.   constructor_erroneous = p->erroneous;
  5440.   constructor_pending_elts = p->pending_elts;
  5441.   constructor_depth = p->depth;
  5442.   constructor_incremental = p->incremental;
  5443.   RESTORE_SPELLING_DEPTH (constructor_depth);
  5444.  
  5445.   constructor_stack = p->next;
  5446.   free (p);
  5447.  
  5448.   if (constructor == 0)
  5449.     {
  5450.       if (constructor_stack == 0)
  5451.     return error_mark_node;
  5452.       return NULL_TREE;
  5453.     }
  5454.   return constructor;
  5455. }
  5456.  
  5457. /* Within an array initializer, specify the next index to be initialized.
  5458.    FIRST is that index.  If LAST is nonzero, then initialize a range
  5459.    of indices, running from FIRST through LAST.  */
  5460.  
  5461. void
  5462. set_init_index (first, last)
  5463.      tree first, last;
  5464. {
  5465.   while ((TREE_CODE (first) == NOP_EXPR
  5466.       || TREE_CODE (first) == CONVERT_EXPR
  5467.       || TREE_CODE (first) == NON_LVALUE_EXPR)
  5468.      && (TYPE_MODE (TREE_TYPE (first))
  5469.          == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
  5470.     (first) = TREE_OPERAND (first, 0);
  5471.   if (last)
  5472.     while ((TREE_CODE (last) == NOP_EXPR
  5473.         || TREE_CODE (last) == CONVERT_EXPR
  5474.         || TREE_CODE (last) == NON_LVALUE_EXPR)
  5475.        && (TYPE_MODE (TREE_TYPE (last))
  5476.            == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
  5477.       (last) = TREE_OPERAND (last, 0);
  5478.  
  5479.   if (TREE_CODE (first) != INTEGER_CST)
  5480.     error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
  5481.   else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
  5482.     error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
  5483.   else if (tree_int_cst_lt (first, constructor_unfilled_index))
  5484.     error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
  5485.   else
  5486.     {
  5487.       TREE_INT_CST_LOW (constructor_index)
  5488.     = TREE_INT_CST_LOW (first);
  5489.       TREE_INT_CST_HIGH (constructor_index)
  5490.     = TREE_INT_CST_HIGH (first);
  5491.  
  5492.       if (last != 0 && tree_int_cst_lt (last, first))
  5493.     error_init ("empty index range in initializer%s", " for `%s'", NULL);
  5494.       else
  5495.     {
  5496.       if (pedantic)
  5497.         pedwarn ("ANSI C forbids specifying element to initialize");
  5498.       constructor_range_end = last;
  5499.     }
  5500.     }
  5501. }
  5502.  
  5503. /* Within a struct initializer, specify the next field to be initialized.  */
  5504.  
  5505. void
  5506. set_init_label (fieldname)
  5507.      tree fieldname;
  5508. {
  5509.   tree tail;
  5510.   int passed = 0;
  5511.  
  5512.   for (tail = TYPE_FIELDS (constructor_type); tail;
  5513.        tail = TREE_CHAIN (tail))
  5514.     {
  5515.       if (tail == constructor_unfilled_fields)
  5516.     passed = 1;
  5517.       if (DECL_NAME (tail) == fieldname)
  5518.     break;
  5519.     }
  5520.  
  5521.   if (tail == 0)
  5522.     error ("unknown field `%s' specified in initializer",
  5523.        IDENTIFIER_POINTER (fieldname));
  5524.   else if (!passed)
  5525.     error ("field `%s' already initialized",
  5526.        IDENTIFIER_POINTER (fieldname));
  5527.   else
  5528.     {
  5529.       constructor_fields = tail;
  5530.       if (pedantic)
  5531.     pedwarn ("ANSI C forbids specifying structure member to initialize");
  5532.     }
  5533. }
  5534.  
  5535. /* "Output" the next constructor element.
  5536.    At top level, really output it to assembler code now.
  5537.    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
  5538.    TYPE is the data type that the containing data type wants here.
  5539.    FIELD is the field (a FIELD_DECL) or the index that this element fills.
  5540.  
  5541.    PENDING if non-nil means output pending elements that belong
  5542.    right after this element.  (PENDING is normally 1;
  5543.    it is 0 while outputting pending elements, to avoid recursion.)  */
  5544.  
  5545. static void
  5546. output_init_element (value, type, field, pending)
  5547.      tree value, type, field;
  5548.      int pending;
  5549. {
  5550.   int duplicate = 0;
  5551.  
  5552.   if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  5553.       || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  5554.       && !(TREE_CODE (value) == STRING_CST
  5555.            && TREE_CODE (type) == ARRAY_TYPE
  5556.            && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
  5557.       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
  5558.              TYPE_MAIN_VARIANT (type))))
  5559.     value = default_conversion (value);
  5560.  
  5561.   if (value == error_mark_node)
  5562.     constructor_erroneous = 1;
  5563.   else if (!TREE_CONSTANT (value))
  5564.     constructor_constant = 0;
  5565.   else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
  5566.     constructor_simple = 0;
  5567.  
  5568.   if (require_constant_value && ! TREE_CONSTANT (value))
  5569.     {
  5570.       error_init ("initializer element%s is not constant",
  5571.           " for `%s'", NULL);
  5572.       value = error_mark_node;
  5573.     }
  5574.   else if (require_constant_elements
  5575.        && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
  5576.     {
  5577.       error_init ("initializer element%s is not computable at load time",
  5578.           " for `%s'", NULL);
  5579.       value = error_mark_node;
  5580.     }
  5581.  
  5582.   /* If this element duplicates one on constructor_pending_elts,
  5583.      print a message and ignore it.  Don't do this when we're
  5584.      processing elements taken off constructor_pending_elts,
  5585.      because we'd always get spurious errors.  */
  5586.   if (pending)
  5587.     {
  5588.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5589.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5590.     {
  5591.       if (purpose_member (field, constructor_pending_elts))
  5592.         {
  5593.           error_init ("duplicate initializer%s", " for `%s'", NULL);
  5594.           duplicate = 1;
  5595.         }
  5596.     }
  5597.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5598.     {
  5599.       tree tail;
  5600.       for (tail = constructor_pending_elts; tail;
  5601.            tail = TREE_CHAIN (tail))
  5602.         if (TREE_PURPOSE (tail) != 0
  5603.         && TREE_CODE (TREE_PURPOSE (tail)) == INTEGER_CST
  5604.         && tree_int_cst_equal (TREE_PURPOSE (tail), constructor_index))
  5605.           break;
  5606.  
  5607.       if (tail != 0)
  5608.         {
  5609.           error_init ("duplicate initializer%s", " for `%s'", NULL);
  5610.           duplicate = 1;
  5611.         }
  5612.     }
  5613.     }
  5614.  
  5615.   /* If this element doesn't come next in sequence,
  5616.      put it on constructor_pending_elts.  */
  5617.   if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5618.       && !tree_int_cst_equal (field, constructor_unfilled_index))
  5619.     {
  5620.       if (! duplicate)
  5621.     /* The copy_node is needed in case field is actually
  5622.        constructor_index, which is modified in place.  */
  5623.     constructor_pending_elts
  5624.       = tree_cons (copy_node (field),
  5625.                digest_init (type, value, 0, 0),
  5626.                constructor_pending_elts);
  5627.     }
  5628.   else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5629.        && field != constructor_unfilled_fields)
  5630.     {
  5631.       /* We do this for records but not for unions.  In a union,
  5632.      no atter which field is specified, it can be initialized
  5633.      right away since it starts at the beginning of the union.  */
  5634.       if (!duplicate)
  5635.     constructor_pending_elts
  5636.       = tree_cons (field,
  5637.                digest_init (type, value, 0, 0),
  5638.                constructor_pending_elts);
  5639.     }
  5640.   else
  5641.     {
  5642.       /* Otherwise, output this element either to
  5643.      constructor_elements or to the assembler file.  */
  5644.  
  5645.       if (!duplicate)
  5646.     {
  5647.       if (! constructor_incremental)
  5648.         {
  5649.           if (field && TREE_CODE (field) == INTEGER_CST)
  5650.         field = copy_node (field);
  5651.           constructor_elements
  5652.         = tree_cons (field, digest_init (type, value, 0, 0),
  5653.                  constructor_elements);
  5654.         }
  5655.       else
  5656.         {
  5657.           /* Structure elements may require alignment.
  5658.          Do this, if necessary.  */
  5659.           if (TREE_CODE (constructor_type) == RECORD_TYPE)
  5660.         {
  5661.           /* Advance to offset of this element.  */
  5662.           if (! tree_int_cst_equal (constructor_bit_index,
  5663.                         DECL_FIELD_BITPOS (constructor_fields)))
  5664.             {
  5665.               int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
  5666.                   / BITS_PER_UNIT);
  5667.               int here = (TREE_INT_CST_LOW (constructor_bit_index)
  5668.                   / BITS_PER_UNIT);
  5669.  
  5670.               assemble_zeros (next - here);
  5671.             }
  5672.         }
  5673.           output_constant (digest_init (type, value, 0, 0),
  5674.                    int_size_in_bytes (type));
  5675.  
  5676.           /* For a record or union,
  5677.          keep track of end position of last field.  */
  5678.           if (TREE_CODE (constructor_type) == RECORD_TYPE
  5679.           || TREE_CODE (constructor_type) == UNION_TYPE)
  5680.         {
  5681.           tree temp = size_binop (PLUS_EXPR,
  5682.                       DECL_FIELD_BITPOS (constructor_fields),
  5683.                       DECL_SIZE (constructor_fields));
  5684.           TREE_INT_CST_LOW (constructor_bit_index)
  5685.             = TREE_INT_CST_LOW (temp);
  5686.           TREE_INT_CST_HIGH (constructor_bit_index)
  5687.             = TREE_INT_CST_HIGH (temp);
  5688.         }
  5689.         }
  5690.     }
  5691.  
  5692.       /* Advance the variable that indicates sequential elements output.  */
  5693.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5694.     {
  5695.       tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
  5696.                  integer_one_node);
  5697.       TREE_INT_CST_LOW (constructor_unfilled_index)
  5698.         = TREE_INT_CST_LOW (tem);
  5699.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  5700.         = TREE_INT_CST_HIGH (tem);
  5701.     }
  5702.       else if (TREE_CODE (constructor_type) == RECORD_TYPE)
  5703.     constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
  5704.       else if (TREE_CODE (constructor_type) == UNION_TYPE)
  5705.     constructor_unfilled_fields = 0;
  5706.  
  5707.       /* Now output any pending elements which have become next.  */
  5708.       if (pending)
  5709.     output_pending_init_elements (0);
  5710.     }
  5711. }
  5712.  
  5713. /* Output any pending elements which have become next.
  5714.    As we output elements, constructor_unfilled_{fields,index}
  5715.    advances, which may cause other elements to become next;
  5716.    if so, they too are output.
  5717.  
  5718.    If ALL is 0, we return when there are
  5719.    no more pending elements to output now.
  5720.  
  5721.    If ALL is 1, we output space as necessary so that
  5722.    we can output all the pending elements.  */
  5723.  
  5724. static void
  5725. output_pending_init_elements (all)
  5726.      int all;
  5727. {
  5728.   tree tail;
  5729.   tree next;
  5730.  
  5731.  retry:
  5732.  
  5733.   /* Look thru the whole pending list.
  5734.      If we find an element that should be output now,
  5735.      output it.  Otherwise, set NEXT to the element
  5736.      that comes first among those still pending.  */
  5737.      
  5738.   next = 0;
  5739.   for (tail = constructor_pending_elts; tail;
  5740.        tail = TREE_CHAIN (tail))
  5741.     {
  5742.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5743.     {
  5744.       if (tree_int_cst_equal (TREE_PURPOSE (tail),
  5745.                   constructor_unfilled_index))
  5746.         {
  5747.           output_init_element (TREE_VALUE (tail), TREE_TYPE (constructor_type),
  5748.                    constructor_unfilled_index, 0);
  5749.           goto retry;
  5750.         }
  5751.       else if (tree_int_cst_lt (TREE_PURPOSE (tail),
  5752.                     constructor_unfilled_index))
  5753.         ;
  5754.       else if (next == 0
  5755.            || tree_int_cst_lt (TREE_PURPOSE (tail),
  5756.                       next))
  5757.         next = TREE_PURPOSE (tail);
  5758.     }
  5759.       else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5760.            || TREE_CODE (constructor_type) == UNION_TYPE)
  5761.     {
  5762.       if (TREE_PURPOSE (tail) == constructor_unfilled_fields)
  5763.         {
  5764.           output_init_element (TREE_VALUE (tail),
  5765.                    TREE_TYPE (constructor_unfilled_fields),
  5766.                    constructor_unfilled_fields,
  5767.                    0);
  5768.           goto retry;
  5769.         }
  5770.       else if (constructor_unfilled_fields == 0
  5771.            || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
  5772.                        DECL_FIELD_BITPOS (constructor_unfilled_fields)))
  5773.         ;
  5774.       else if (next == 0
  5775.            || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
  5776.                        DECL_FIELD_BITPOS (next)))
  5777.         next = TREE_PURPOSE (tail);
  5778.     }
  5779.     }
  5780.  
  5781.   /* Ordinarily return, but not if we want to output all
  5782.      and there are elements left.  */
  5783.   if (! (all && next != 0))
  5784.     return;
  5785.  
  5786.   /* Generate space up to the position of NEXT.  */
  5787.   if (constructor_incremental)
  5788.     {
  5789.       tree filled;
  5790.       tree nextpos_tree;
  5791.  
  5792.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5793.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5794.     {
  5795.       /* Find the last field written out.  */
  5796.       for (tail = TYPE_FIELDS (constructor_type); tail;
  5797.            tail = TREE_CHAIN (tail))
  5798.         if (TREE_CHAIN (tail) == constructor_unfilled_fields)
  5799.           break;
  5800.       /* Find the offset of the end of that field.  */
  5801.       filled = size_binop (CEIL_DIV_EXPR,
  5802.                    size_binop (PLUS_EXPR,
  5803.                        DECL_FIELD_BITPOS (tail),
  5804.                        DECL_SIZE (tail)),
  5805.                    size_int (BITS_PER_UNIT));
  5806.       nextpos_tree = size_binop (CEIL_DIV_EXPR,
  5807.                      DECL_FIELD_BITPOS (next),
  5808.                      size_int (BITS_PER_UNIT));
  5809.       constructor_unfilled_fields = next;
  5810.     }
  5811.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5812.     {
  5813.       filled = size_binop (MULT_EXPR, constructor_unfilled_index,
  5814.                    size_in_bytes (TREE_TYPE (constructor_type)));
  5815.       nextpos_tree
  5816.         = size_binop (MULT_EXPR, next,
  5817.               size_in_bytes (TREE_TYPE (constructor_type)));
  5818.       TREE_INT_CST_LOW (constructor_unfilled_index)
  5819.         = TREE_INT_CST_LOW (next);
  5820.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  5821.         = TREE_INT_CST_HIGH (next);
  5822.     }
  5823.       else
  5824.     filled = 0;
  5825.  
  5826.       if (filled)
  5827.     {
  5828.       int nextpos = TREE_INT_CST_LOW (nextpos_tree);
  5829.  
  5830.       assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
  5831.     }
  5832.     }
  5833.   else
  5834.     {
  5835.       /* If it's not incremental, just skip over the gap,
  5836.      so that after jumping to retry we will output the next
  5837.      successive element.  */
  5838.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5839.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5840.     constructor_unfilled_fields = next;
  5841.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5842.     {
  5843.       TREE_INT_CST_LOW (constructor_unfilled_index)
  5844.         = TREE_INT_CST_LOW (next);
  5845.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  5846.         = TREE_INT_CST_HIGH (next);
  5847.     }
  5848.     }
  5849.  
  5850.   goto retry;
  5851. }
  5852.  
  5853. /* Add one non-braced element to the current constructor level.
  5854.    This adjusts the current position within the constructor's type.
  5855.    This may also start or terminate implicit levels
  5856.    to handle a partly-braced initializer.
  5857.  
  5858.    Once this has found the correct level for the new element,
  5859.    it calls output_init_element.
  5860.  
  5861.    Note: if we are incrementally outputting this constructor,
  5862.    this function may be called with a null argument
  5863.    representing a sub-constructor that was already incrementally output.
  5864.    When that happens, we output nothing, but we do the bookkeeping
  5865.    to skip past that element of the current constructor.  */
  5866.  
  5867. void
  5868. process_init_element (value)
  5869.      tree value;
  5870. {
  5871.   tree orig_value = value;
  5872.   int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
  5873.  
  5874.   /* Handle superfluous braces around string cst as in
  5875.      char x[] = {"foo"}; */
  5876.   if (string_flag
  5877.       && TREE_CODE (constructor_type) == ARRAY_TYPE
  5878.       && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
  5879.       && integer_zerop (constructor_unfilled_index))
  5880.     {
  5881.       constructor_stack->replacement_value = value;
  5882.       return;
  5883.     }
  5884.  
  5885.   if (constructor_stack->replacement_value != 0)
  5886.     {
  5887.       error_init ("excess elements in struct initializer%s",
  5888.           " after `%s'", NULL_PTR);
  5889.       return;
  5890.     }
  5891.  
  5892.   /* Ignore elements of a brace group if it is entirely superfluous
  5893.      and has already been diagnosed.  */
  5894.   if (constructor_type == 0)
  5895.     return;
  5896.  
  5897.   /* If we've exhausted any levels that didn't have braces,
  5898.      pop them now.  */
  5899.   while (constructor_stack->implicit)
  5900.     {
  5901.       if ((TREE_CODE (constructor_type) == RECORD_TYPE
  5902.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5903.       && constructor_fields == 0)
  5904.     process_init_element (pop_init_level (1));
  5905.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5906.            && tree_int_cst_lt (constructor_max_index, constructor_index))
  5907.     process_init_element (pop_init_level (1));
  5908.       else
  5909.     break;
  5910.     }
  5911.  
  5912.   while (1)
  5913.     {
  5914.       if (TREE_CODE (constructor_type) == RECORD_TYPE)
  5915.     {
  5916.       tree fieldtype;
  5917.       enum tree_code fieldcode;
  5918.  
  5919.       if (constructor_fields == 0)
  5920.         {
  5921.           pedwarn_init ("excess elements in struct initializer%s",
  5922.                 " after `%s'", NULL_PTR);
  5923.           break;
  5924.         }
  5925.  
  5926.       fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
  5927.       fieldcode = TREE_CODE (fieldtype);
  5928.  
  5929.       /* Accept a string constant to initialize a subarray.  */
  5930.       if (value != 0
  5931.           && fieldcode == ARRAY_TYPE
  5932.           && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
  5933.           && string_flag)
  5934.         value = orig_value;
  5935.       /* Otherwise, if we have come to a subaggregate,
  5936.          and we don't have an element of its type, push into it.  */
  5937.       else if (value != 0 && !constructor_no_implicit
  5938.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
  5939.            && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
  5940.                || fieldcode == UNION_TYPE))
  5941.         {
  5942.           push_init_level (1);
  5943.           continue;
  5944.         }
  5945.  
  5946.       if (value)
  5947.         {
  5948.           push_member_name (constructor_fields);
  5949.           output_init_element (value, fieldtype, constructor_fields, 1);
  5950.           RESTORE_SPELLING_DEPTH (constructor_depth);
  5951.         }
  5952.       else
  5953.         /* Do the bookkeeping for an element that was
  5954.            directly output as a constructor.  */
  5955.         {
  5956.           /* For a record, keep track of end position of last field.  */
  5957.           tree temp = size_binop (PLUS_EXPR,
  5958.                       DECL_FIELD_BITPOS (constructor_fields),
  5959.                       DECL_SIZE (constructor_fields));
  5960.           TREE_INT_CST_LOW (constructor_bit_index)
  5961.         = TREE_INT_CST_LOW (temp);
  5962.           TREE_INT_CST_HIGH (constructor_bit_index)
  5963.         = TREE_INT_CST_HIGH (temp);
  5964.  
  5965.           constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
  5966.         }
  5967.  
  5968.       constructor_fields = TREE_CHAIN (constructor_fields);
  5969.       /* Skip any nameless bit fields atthe beginning.  */
  5970.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  5971.          && DECL_NAME (constructor_fields) == 0)
  5972.         constructor_fields = TREE_CHAIN (constructor_fields);
  5973.       break;
  5974.     }
  5975.       if (TREE_CODE (constructor_type) == UNION_TYPE)
  5976.     {
  5977.       tree fieldtype;
  5978.       enum tree_code fieldcode;
  5979.  
  5980.       if (constructor_fields == 0)
  5981.         {
  5982.           pedwarn_init ("excess elements in union initializer%s",
  5983.                 " after `%s'", NULL_PTR);
  5984.           break;
  5985.         }
  5986.  
  5987.       fieldtype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_fields));
  5988.       fieldcode = TREE_CODE (fieldtype);
  5989.  
  5990.       /* Accept a string constant to initialize a subarray.  */
  5991.       if (value != 0
  5992.           && fieldcode == ARRAY_TYPE
  5993.           && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
  5994.           && string_flag)
  5995.         value = orig_value;
  5996.       /* Otherwise, if we have come to a subaggregate,
  5997.          and we don't have an element of its type, push into it.  */
  5998.       else if (value != 0 && !constructor_no_implicit
  5999.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
  6000.            && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
  6001.                || fieldcode == UNION_TYPE))
  6002.         {
  6003.           push_init_level (1);
  6004.           continue;
  6005.         }
  6006.  
  6007.       if (value)
  6008.         {
  6009.           push_member_name (constructor_fields);
  6010.           output_init_element (value, fieldtype, constructor_fields, 1);
  6011.           RESTORE_SPELLING_DEPTH (constructor_depth);
  6012.         }
  6013.       else
  6014.         /* Do the bookkeeping for an element that was
  6015.            directly output as a constructor.  */
  6016.         {
  6017.           TREE_INT_CST_LOW (constructor_bit_index)
  6018.         = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields));
  6019.           TREE_INT_CST_HIGH (constructor_bit_index)
  6020.         = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields));
  6021.  
  6022.           constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
  6023.         }
  6024.  
  6025.       constructor_fields = 0;
  6026.       break;
  6027.     }
  6028.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  6029.     {
  6030.       tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
  6031.       enum tree_code eltcode = TREE_CODE (elttype);
  6032.  
  6033.       /* Accept a string constant to initialize a subarray.  */
  6034.       if (value != 0
  6035.           && eltcode == ARRAY_TYPE
  6036.           && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
  6037.           && string_flag)
  6038.         value = orig_value;
  6039.       /* Otherwise, if we have come to a subaggregate,
  6040.          and we don't have an element of its type, push into it.  */
  6041.       else if (value != 0 && !constructor_no_implicit
  6042.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
  6043.            && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
  6044.                || eltcode == UNION_TYPE))
  6045.         {
  6046.           push_init_level (1);
  6047.           continue;
  6048.         }
  6049.  
  6050.       if (constructor_max_index != 0
  6051.           && tree_int_cst_lt (constructor_max_index, constructor_index))
  6052.         {
  6053.           pedwarn_init ("excess elements in array initializer%s",
  6054.                 " after `%s'", NULL_PTR);
  6055.           break;
  6056.         }
  6057.  
  6058.       /* Now output the actual element.
  6059.          Ordinarily, output once.
  6060.          If there is a range, repeat it till we advance past the range.  */
  6061.       do
  6062.         {
  6063.           tree tem;
  6064.  
  6065.           if (value)
  6066.         {
  6067.           push_array_bounds (TREE_INT_CST_LOW (constructor_index));
  6068.           output_init_element (value, elttype, constructor_index, 1);
  6069.           RESTORE_SPELLING_DEPTH (constructor_depth);
  6070.         }
  6071.  
  6072.           tem = size_binop (PLUS_EXPR, constructor_index,
  6073.                 integer_one_node);
  6074.           TREE_INT_CST_LOW (constructor_index)
  6075.         = TREE_INT_CST_LOW (tem);
  6076.           TREE_INT_CST_HIGH (constructor_index)
  6077.         = TREE_INT_CST_HIGH (tem);
  6078.  
  6079.           if (!value)
  6080.         /* If we are doing the bookkeeping for an element that was
  6081.            directly output as a constructor,
  6082.            we must update constructor_unfilled_index.  */
  6083.         {
  6084.           TREE_INT_CST_LOW (constructor_unfilled_index)
  6085.             = TREE_INT_CST_LOW (constructor_index);
  6086.           TREE_INT_CST_HIGH (constructor_unfilled_index)
  6087.             = TREE_INT_CST_HIGH (constructor_index);
  6088.         }
  6089.         }
  6090.       while (! (constructor_range_end == 0
  6091.             || tree_int_cst_lt (constructor_range_end,
  6092.                     constructor_index)));
  6093.  
  6094.       break;
  6095.     }
  6096.  
  6097.       /* Handle the sole element allowed in a braced initializer
  6098.      for a scalar variable.  */
  6099.       if (constructor_fields == 0)
  6100.     {
  6101.       pedwarn_init ("excess elements in scalar initializer%s",
  6102.             " after `%s'", NULL_PTR);
  6103.       break;
  6104.     }
  6105.  
  6106.       if (value)
  6107.     output_init_element (value, constructor_type, NULL_TREE, 1);
  6108.       constructor_fields = 0;
  6109.       break;
  6110.     }
  6111.  
  6112.   /* If the (lexically) previous elments are not now saved,
  6113.      we can discard the storage for them.  */
  6114.   if (constructor_incremental && constructor_pending_elts == 0 && value != 0)
  6115.     clear_momentary ();
  6116. }
  6117.  
  6118. /* Expand an ASM statement with operands, handling output operands
  6119.    that are not variables or INDIRECT_REFS by transforming such
  6120.    cases into cases that expand_asm_operands can handle.
  6121.  
  6122.    Arguments are same as for expand_asm_operands.  */
  6123.  
  6124. void
  6125. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  6126.      tree string, outputs, inputs, clobbers;
  6127.      int vol;
  6128.      char *filename;
  6129.      int line;
  6130. {
  6131.   int noutputs = list_length (outputs);
  6132.   register int i;
  6133.   /* o[I] is the place that output number I should be written.  */
  6134.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  6135.   register tree tail;
  6136.  
  6137.   if (TREE_CODE (string) == ADDR_EXPR)
  6138.     string = TREE_OPERAND (string, 0);
  6139.   if (TREE_CODE (string) != STRING_CST)
  6140.     {
  6141.       error ("asm template is not a string constant");
  6142.       return;
  6143.     }
  6144.  
  6145.   /* Record the contents of OUTPUTS before it is modified.  */
  6146.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6147.     o[i] = TREE_VALUE (tail);
  6148.  
  6149.   /* Perform default conversions on array and function inputs.  */
  6150.   /* Don't do this for other types--
  6151.      it would screw up operands expected to be in memory.  */
  6152.   for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
  6153.     if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
  6154.     || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
  6155.       TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
  6156.  
  6157.   /* Generate the ASM_OPERANDS insn;
  6158.      store into the TREE_VALUEs of OUTPUTS some trees for
  6159.      where the values were actually stored.  */
  6160.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  6161.  
  6162.   /* Copy all the intermediate outputs into the specified outputs.  */
  6163.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6164.     {
  6165.       if (o[i] != TREE_VALUE (tail))
  6166.     {
  6167.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  6168.                0, VOIDmode, 0);
  6169.       free_temp_slots ();
  6170.     }
  6171.       /* Detect modification of read-only values.
  6172.      (Otherwise done by build_modify_expr.)  */
  6173.       else
  6174.     {
  6175.       tree type = TREE_TYPE (o[i]);
  6176.       if (TYPE_READONLY (type)
  6177.           || ((TREE_CODE (type) == RECORD_TYPE
  6178.            || TREE_CODE (type) == UNION_TYPE)
  6179.           && C_TYPE_FIELDS_READONLY (type)))
  6180.         readonly_warning (o[i], "modification by `asm'");
  6181.     }
  6182.     }
  6183.  
  6184.   /* Those MODIFY_EXPRs could do autoincrements.  */
  6185.   emit_queue ();
  6186. }
  6187.  
  6188. /* Expand a C `return' statement.
  6189.    RETVAL is the expression for what to return,
  6190.    or a null pointer for `return;' with no value.  */
  6191.  
  6192. void
  6193. c_expand_return (retval)
  6194.      tree retval;
  6195. {
  6196.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  6197.  
  6198.   if (TREE_THIS_VOLATILE (current_function_decl))
  6199.     warning ("function declared `volatile' has a `return' statement");
  6200.  
  6201.   if (!retval)
  6202.     {
  6203.       current_function_returns_null = 1;
  6204.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  6205.     warning ("`return' with no value, in function returning non-void");
  6206.       expand_null_return ();
  6207.     }
  6208.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  6209.     {
  6210.       current_function_returns_null = 1;
  6211.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  6212.     pedwarn ("`return' with a value, in function returning void");
  6213.       expand_return (retval);
  6214.     }
  6215.   else
  6216.     {
  6217.       tree t = convert_for_assignment (valtype, retval, "return",
  6218.                        NULL_TREE, NULL_TREE, 0);
  6219.       tree res = DECL_RESULT (current_function_decl);
  6220.  
  6221.       if (t == error_mark_node)
  6222.     return;
  6223.  
  6224.       t = build (MODIFY_EXPR, TREE_TYPE (res),
  6225.          res, convert (TREE_TYPE (res), t));
  6226.       TREE_SIDE_EFFECTS (t) = 1;
  6227.       expand_return (t);
  6228.       current_function_returns_value = 1;
  6229.     }
  6230. }
  6231.  
  6232. /* Start a C switch statement, testing expression EXP.
  6233.    Return EXP if it is valid, an error node otherwise.  */
  6234.  
  6235. tree
  6236. c_expand_start_case (exp)
  6237.      tree exp;
  6238. {
  6239.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  6240.   tree type = TREE_TYPE (exp);
  6241.  
  6242.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  6243.     {
  6244.       error ("switch quantity not an integer");
  6245.       exp = error_mark_node;
  6246.     }
  6247.   else
  6248.     {
  6249.       tree index;
  6250.       type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
  6251.  
  6252.       if (warn_traditional
  6253.       && (type == long_integer_type_node
  6254.           || type == long_unsigned_type_node))
  6255.     pedwarn ("`long' switch expression not converted to `int' in ANSI C");
  6256.  
  6257.       exp = default_conversion (exp);
  6258.       type = TREE_TYPE (exp);
  6259.       index = get_unwidened (exp, NULL_TREE);
  6260.       /* We can't strip a conversion from a signed type to an unsigned,
  6261.      because if we did, int_fits_type_p would do the wrong thing
  6262.      when checking case values for being in range,
  6263.      and it's too hard to do the right thing.  */
  6264.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  6265.       == TREE_UNSIGNED (TREE_TYPE (index)))
  6266.     exp = index;
  6267.     }
  6268.  
  6269.   expand_start_case (1, exp, type, "switch statement");
  6270.  
  6271.   return exp;
  6272. }
  6273.  
  6274. /* Initializers for const declarations should be kept
  6275.    longer than to the end of the declaration, so that 
  6276.    the optimizer can inline them.  */
  6277.  
  6278. void
  6279. push_momentary_for_initlist ()
  6280. {
  6281.   push_momentary ();
  6282.   if (   constructor_decl
  6283.       && TREE_READONLY (constructor_decl)
  6284.       && ! TREE_SIDE_EFFECTS (constructor_decl)
  6285.       && TREE_CODE (constructor_decl) == VAR_DECL)
  6286.     {
  6287.       suspend_momentary ();
  6288.     }
  6289. }
  6290.  
  6291.